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

阿萨德
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循环可以工作,但是两次使用它却没有得到它。

改变了Gunasekara

怎么样使用这样的东西,

boolean run = true;

while(run) {

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我的列表视图应用程序一次又一次地崩溃

我的音乐播放器应用程序一次又一次地崩溃

我可以重用UICollectionView吗?不想一次又一次地创建collectionView

在 jQuery 中,我不知道如何一次又一次地更改 attr

我的数据在表视图中一次又一次地重新加载?

我试图让 while 循环在完成后由用户一次又一次地重复

我是初学者,我想在我的计算器程序中添加一个循环,这样我就不需要一次又一次地运行它。我能做什么?

我可以一次又一次清除setInterval id吗

我需要一次又一次刷新dns以使站点加载

PHP日期功能一次又一次给我相同的时间

Virtual Machine Manager希望一次又一次地禁止Wayland上的快捷方式

如何停止在 JavaScript 中一次又一次地调用相同的函数?

为什么 npm install 命令在 node app 中一次又一次地重新运行?

通知被一次又一次地触发

在 Fortran 95 中一次又一次地读取文件的内容

避免一次又一次地从JSON获取数据

Flutter:为什么setState((){})一次又一次地设置数据

如何一次又一次地调用URL

更新状态一次又一次地获取数据后

Azure 容器实例一次又一次地失败

一次又一次地馈送avconv

内核一次又一次地死亡

一次又一次地编辑python脚本文件

无法一次又一次地在LinkedList中插入相同的元素

Square 一次又一次地改变速度

如何一次又一次地重复(递归)查询?

要重用jQuery函数,使函数一次又一次地使用

如何一次又一次地选择读/写?

init方法在servlet中一次又一次地调用