发布网友
共2个回答
热心网友
import java.util.Scanner;
public class test {
public static void main(String[] args) {
int j = 0;// 从0米开始跑
Scanner in = new Scanner(System.in);
while(true) {
System.out.println("你跑了多少米?");
j = in.nextInt();
System.out.println("口渴吗?请输入(yes or no)");
String thirst = in.next();
if (j > 400) {
if (!thirst.equals("yes")) {
System.out.println("好吧,那你继续跑吧!");
continue; // 不喝水,继续跑
} else {
System.out.println("过来喝水吧");
}
break;
}
else{
continue;
}
}
}
}
谢谢采纳
热心网友
package day1;
/*怎么让程序检验跑的米数不够400米后返回再检验跑的米数,而不是向下喝水呢*/
import java.util.Scanner;
public class for_4 {
public static void main(String[] args) {
int j = 0;// 从0米开始跑
int k = 0;
Scanner in = new Scanner(System.in);
while (true) {
while (j < 400) {
if (j < 400) {
System.out.println("你跑了多少米?");
j = in.nextInt();
while (j < 400) {
System.out.println("跑的不够400米,继续跑");
k = in.nextInt();
j = k + j;
}
}
}
if (j >= 400) {
System.out.println("口渴吗?请输入(yes or no)");
String thirst = in.next();
while (!thirst.equals("yes") && !thirst.equals("no")) {
System.out.println("请重新输入");
thirst = in.next();
}
if (thirst.equals("yes")) {
System.out.println("过来喝水吧");
} else {
System.out.println("好吧,那你继续跑吧!");
}
break;
}
}
}
}