JAVA ERROR .need suggestion in form of comments or codes if possible pls, -


as newbie.i have tried code..pls suggeesst problem.. getting error.pls me solve problem..

import java.util.scanner; import java.io.*; package calculator;  public class calc {     public static void main(string[] args) {     }              private int valuea;             private int valueb;             private string operator;             private char operatora;              public int getvaluea() {             return valuea;             }              public int getvalueb() {             return valueb;             }              {             scanner keyboard = new scanner(system.in);             system.out.println("enter problem.");              {              valuea = keyboard.nextint();             valueb = keyboard.nextint();             operator = keyboard.next();             operatora = operator.charat(0);              int add = valuea + valueb;             int minus = valuea - valueb;             int multiply = valuea * valueb;             int divide = valuea / valueb;             string clearscreen = null;               switch (operatora) {             case '+':             system.out.println(add);             break;              case '-':             system.out.println(minus);             break;              case '*':             system.out.println(multiply);             break;              case '/':             system.out.println(divide);              case 'c':             system.out.println(clearscreen);             break;              default:             system.out.println("unknown operator '" + operator + "'. please try again.");             break;             }              }         } 

pls provide corrective points???

: syntax error, insert "}" complete methodbody

the main issue compiler complaining incorrect placement of braces (one missing @ end). however, didn't write code in right place either. wanted have of in main(), instead had in constructor , won't run without @ least instantiating object of type calc. really, want refactor code this:

import java.util.scanner;  public class calc {     private static int valuea;     private static int valueb;     private static string operator;     private static char operatora;      public int getvaluea() {         return valuea;     }      public int getvalueb() {         return valueb;     }      public static void main(string[] args) {         scanner keyboard = new scanner(system.in);         system.out.println("enter problem.");          valuea = keyboard.nextint();         valueb = keyboard.nextint();         operator = keyboard.next();         operatora = operator.charat(0);          int add = valuea + valueb;         int minus = valuea - valueb;         int multiply = valuea * valueb;         int divide = valuea / valueb;         string clearscreen = null;          switch (operatora) {         case '+':             system.out.println(add);             break;          case '-':             system.out.println(minus);             break;          case '*':             system.out.println(multiply);             break;          case '/':             system.out.println(divide);          case 'c':             system.out.println(clearscreen);             break;          default:             system.out.println("unknown operator '" + operator                     + "'. please try again.");             break;         }      }  } 

that is, if want access variables in class main, have declared static (as main is/has static) have done here.

alternatively, instantiate object of type calc , access members via getters you've created , variables not have static (as perhaps intended). cleaner , i'll leave exercise. note standard naming conventions in java: camelcase , class names start capital letter.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -