import java.util.Scanner;class calculator { void add(float a, float b) { System.out.print("Result: "+(a+b)); } void sub(float a, float b) { System.out.print("Result: "+(a-b)); } void mult(float a, float b) { System.out.print("Result: "+(a*b)); } void div(float a, float b) { System.out.print("Result: "+(a/b)); }}class Cal { public static void main(String args[]) { Scanner sc= new Scanner(System.in); do { System.out.print("Enter Two Operands: "); float a=sc.nextFloat(); float b=sc.nextFloat(); System.out.print("Press 1 for Addition\n Press 2 for Subtraction\n Press 3 for Multiplication\n Press 4 for Division\n Press 5 for Exit\n"); System.out.print("Enter your choice: "); int n=sc.nextInt(); calculator c=new calculator(); switch(n) { case 1: c.add(a,b); break; case 2: c.sub(a,b); break; case 3: c.mult(a,b); break; case 4: c.div(a,b); break; case 5: System.exit(0); default: System.out.print("Wrong Choice!!!"); } System.out.print("Are you want to continue?: "); int con=sc.nextInt(); } while (con==1); }}這是簡單的計算器問題,但我遇到以下錯誤:PS H:\java> javac calculator.javacalculator.java:47: error: cannot find symbol }while(con==1); ^ symbol: variable con location: class Cal1 error
1 回答

慕少森
TA貢獻2019條經(jīng)驗 獲得超9個贊
該con
變量在循環(huán)內(nèi)聲明,對while
.
int con=0;
在循環(huán)開始之前聲明do-while
。并int
從con
循環(huán)中的賦值中移除。
添加回答
舉報
0/150
提交
取消