【发布时间】:2011-02-13 14:56:06
【问题描述】:
首先,这不是一个家庭作业问题。我正在练习我的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;
}
}
}
【问题讨论】:
-
你遇到什么样的错误?
-
感谢您发布代码。但是,当您发布从编译器获得的错误消息的文本时,它也有很大帮助 - 这使人们更容易快速识别问题(无需阅读整个代码或自己编译)。
标签: java calculator