public class Tester
{
// instance variables - replace the example below with your own
Scanner operation = new Scanner(System.in);
IntegerCalc calc = new IntegerCalc();
public Tester()
{
char choice;
String value;
char again;
}
public void test()
{
char again = operation.next().charAt(0);
do{
System.out.println("Please pick one of the following operations: 1. Addition 2. Subtraction" +
"3. Multiplication 4.Division 5. Modulo 6. Square 7.Square Root");
int num = operation.nextInt();
int ch;
ch = operation.nextInt();
String choice;
choice = operation.next();
switch (ch){
case 1: calc.addition(num,num);
break;
case 2: calc.subtraction(num, num);
break;
case 3: calc.multiplication(num, num);
break;
case 4: calc.division(num, num);
break;
case 5: calc.modulo(num, num);
break;
case 6:calc.square(num);
break;
case 7: calc.squareRoot(num);
break;
default: System.out.println("Please enter a valid choice number.");
}
System.out.println("Type x to exit");
}while(again != 'x' && again != 'X');
{
System.out.println("Thank you for using my program!");
}
//這段代碼的問題在於,它甚至不提示用戶輸入任何數據,它似乎只是被卡在一個循環中,什麼都不做。任何人都知道我能做些什麼來實現這個目標?爲什麼這個do/while循環卡在inf中。循環?
這是否甚至編譯?靠近底部的一個括號會面對錯誤的方向。 – Tyson