gpt4 book ai didi

java - 带 Switch 语句的 While 循环

转载 作者:太空宇宙 更新时间:2023-11-04 14:00:06 24 4
gpt4 key购买 nike

我无法让开关不断循环,直到用户告诉程序停止。当提示用户放入 N 循环时,应将其发送回开关顶部

        char stop;
while(stop == 'N'){
switch(choice){
case 1:
System.out.println("Enter the time in seconds:");
time = input.nextInt();
displacement = (Math.pow(time,4)) + 16;
System.out.println("Felix's displacement is equal to " + displacement + " meters");
System.out.println("Stop the application(Y/N)");
stop = input.findWithinHorizon(".",0).charAt(0);
break;
case 2:
System.out.println("Enter the time in seconds:");
time = input.nextInt();
velocity = 4*(Math.pow(time,3));
System.out.println("Felix's velocity is equal to " + velocity + " m/s");
break;
case 3:
System.out.println("Enter the time in seconds:");
time = input.nextInt();
acceleration = 12*(Math.pow(time,2));
System.out.println("Felix's acceleration is equal to " + acceleration + " m/(s*s)");
break;
default:
System.out.println("Please select a choice");

}
}
}

最佳答案

  1. 粗略地说:初始化 stop关于声明:

char stop = 'N';

  • 更好:替换您的 whiledo while循环:

    做{

    } while (stop == 'N')

  • 关于java - 带 Switch 语句的 While 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29372691/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com