Java 使用while?按相反顺序打印200到150的数字,并按顺序打印200到150的数字?
如何使用单while循环以相反顺序打印200到150的数字,并以顺序打印200到150的数字Java 使用while?按相反顺序打印200到150的数字,并按顺序打印200到150的数字?,java,Java,如何使用单while循环以相反顺序打印200到150的数字,并以顺序打印200到150的数字 class test { public static void main(String[]args) { while(n>=150) { System.out.println(n); n--; } n=0; while(n<=150) { Sys
class test {
public static void main(String[]args) {
while(n>=150) {
System.out.println(n);
n--;
}
n=0;
while(n<=150) {
System.out.println(n);
n++;
}
}
}
给你:
public static void main(String[] args) {
int n = 150;
while(n <= 200) {
System.out.println("Decreasing : " + (150 + (200 - n)));
System.out.println("Increating : " + (n++));
}
}
为什么要使用while循环?IntStream.rangeclosed150200.forEachOrderedi->System.out.printf%d%d%n,i,150+200-i;很简单。在一张照片中,你有x,在另一张照片中,你有200-x。但是,首先尝试编写可编译的代码。我没有否决,但我猜,因为您分发的是自定义代码,它除了提高他/她的复制粘贴技能外,不会学到任何东西,而且您没有提供任何与代码相关的实际注释/信息。