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.java
calculator.java:47: error: cannot find symbol
}while(con==1);
^
symbol: variable con
location: class Cal
1 error
慕少森
相关分类