首先,这不是一门功课的问题。我正在练习关于java的知识。我认为一个很好的方法就是在没有帮助的情况下写一个简单的程序。不幸的是,我的编译器告诉我错误,我不知道如何解决。在不改变逻辑和代码的情况下,有人能够指出我的一些错误在哪里?由于简单的Java计算器
import java.lang.*;
import java.util.*;
public class Calculator
{
private int solution;
private int x;
private int y;
private char operators;
public Calculator()
{
solution = 0;
Scanner operators = new Scanner(System.in);
Scanner operands = new Scanner(System.in);
}
public int addition(int x, int y)
{
return x + y;
}
public int subtraction(int x, int y)
{
return x - y;
}
public int multiplication(int x, int y)
{
return x * y;
}
public int division(int x, int y)
{
solution = x/y;
return solution;
}
public void main (String[] args)
{
System.out.println("What operation? ('+', '-', '*', '/')");
System.out.println("Insert 2 numbers to be subtracted");
System.out.println("operand 1: ");
x = operands;
System.out.println("operand 2: ");
y = operands.next();
switch(operators)
{
case('+'):
addition(operands);
operands.next();
break;
case('-'):
subtraction(operands);
operands.next();
break;
case('*'):
multiplication(operands);
operands.next();
break;
case('/'):
division(operands);
operands.next();
break;
}
}
}
你会得到什么样的错误? – 2010-04-29 01:29:22
感谢您发布您的代码。但是,当您发布从编译器获得的错误消息文本时,它也会有很大的帮助 - 这使得人们可以更轻松地快速识别问题(无需阅读整个代码或自行编译)。 – 2010-04-29 01:42:01