0
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!");




    }

// 这段代码的问题是它甚至没有提示用户输入任何数据,它似乎只是卡在一个循环中,没有做任何事情。任何人都知道我能做些什么来让它工作?

4

3 回答 3

2

你有:char again = operation.next().charAt(0);do/while循环之外,所以如果again满足while条件,你将得到一个无限循环。

于 2013-11-10T00:35:07.147 回答
0

您需要接受来自用户的字符

again = operation.next().charAt(0);

在此声明之后

System.out.println("Type x to exit");
于 2013-11-10T00:35:45.523 回答
0
System.out.println("Type x to exit");
char again = operation.next().charAt(0);

这应该工作

于 2013-11-10T00:36:01.587 回答