我希望我的程序一次又一次地运行而不会停止

时间:2015-10-14 22:57:11

标签: java

import java.util.*;
public class bad {

        public static void main(String []args)
    {
            Scanner input;
            input = new Scanner(System.in);


        System.out.println("Enter First Num ");
        int a =input.nextInt();
        input.nextLine();

        System.out.println("Enter Secound Num ");
        int b =input.nextInt();
        input.nextLine();

        System.out.println("For Addition press a" );
        System.out.println("For Subtraction press s" );
        System.out.println("For Multiplication press m" );
        System.out.println("For Divide press d" );
        System.out.println("For Square and Cube press c" );
        //the Square and cube depend apone you wither you have to Square or cube.
        System.out.println("For Root press r");
        String store =input.nextLine();

        if (store .equals("a"))


    {

        System.out.print("Answear is: ");
        System.out.print(a+b);
    }
        else if(store .equals("m"))
    {
        System.out.print("Answear is: ");
        System.out.print(a*b);
    }

        else if(store .equals("d"))
    {   
        System.out.print("Answear is: ");
        System.out.print(a/b);
    }
        else if(store .equals("s"))
    {
        System.out.print("Answear is: ");
        System.out.print(a-b);
    }


        else if(store .equals("c"))
        {   

        System.out.println("Answear for the power is : ");
        System.out.print(Math.pow(a,b));
    }
        else if (store.equals("r"))
        {
            System.out.println("Answear is : ");
            System.out.println(Math.sqrt(a));
        }




        }
    }

我的程序一次又一次地运行而没有停止意味着该程序要求用户再次输入一个号码? 有搜索批次,但没有得到基本的想法。可能是while循环将工作,但使用它两次没有得到它。

2 个答案:

答案 0 :(得分:0)

如何使用这样的东西,

boolean run = true;

while(run) {

   //when the condition to terminate the program is met
   //set run to false
   run = false;
}

答案 1 :(得分:0)

while(true){

//your complete code
}

尝试再次使用while循环,如