理解带有嵌套 if else 语句的 Do While 循环
Understanding Do While Loop with nested if else statement
我的教授让我们在 class 中做到这一点,我对这些输出感到非常困惑。
这 (x + " " + y + " " + z)
是否意味着添加所有 3 个变量 if (y > z)
?输出对我来说根本没有任何意义。
public class Practice
{
public static void main (String[] args)
{
int x=10, y=11, z=3;
do
{
System.out.println(x + " " + y + " " + z);
if (y > z)
{
y = y-5;
}
else
{
y = y + 3;
}
x = x - 2;
} while (x > 0);
System.out.println("Bye");
}
}
OUTPUT:
10 11 3
8 6 3
6 1 3
4 4 3
2 -1 3
Bye
System.out.println(x + " " + y + " " + z);
这不是添加 x、y 和 z。它只是在字符串中附加值以进行打印
您的数字已转换为字符串
我的教授让我们在 class 中做到这一点,我对这些输出感到非常困惑。
这 (x + " " + y + " " + z)
是否意味着添加所有 3 个变量 if (y > z)
?输出对我来说根本没有任何意义。
public class Practice
{
public static void main (String[] args)
{
int x=10, y=11, z=3;
do
{
System.out.println(x + " " + y + " " + z);
if (y > z)
{
y = y-5;
}
else
{
y = y + 3;
}
x = x - 2;
} while (x > 0);
System.out.println("Bye");
}
}
OUTPUT:
10 11 3
8 6 3
6 1 3
4 4 3
2 -1 3
Bye
System.out.println(x + " " + y + " " + z);
这不是添加 x、y 和 z。它只是在字符串中附加值以进行打印 您的数字已转换为字符串