P.20
public class Shuffle1 {
public static void main(String[] args) {
int x = 3;
while (x > 0) {
if (x > 2) {
System.out.print("a");
}
x = x - 1;
System.out.print("-");
if (x == 2) {
System.out.print("b c");
}
x = x - 1;
System.out.print("-");
if (x == 1) {
System.out.print("d");
x = x - 1;
}
}
}
}
p.21
A
public class Exercise1b {
public static void main(String[] args) {
int x = 1;
while(x < 10){
if(x>3){
System.out.println("big x");
}
//要使x的值随着循环而减少,避免死循环,x每次循环减少多少,自己定!
//但要注意的是编译可以通过
x--;
}
}
}
B
//public calss Exercise1b{ 类没了,当然得出问题,并且编译不会通过
public static void main(String[]args) {
int x = 5;
while(x > 1) {
x = x - 1;
if(x < 3) {
System.out.println("small x");
}
}
}
//}
C
public class Exercise1b {
//书的本章刚讲:main方法相当与程序的起点,且一个程序有且只有一个
//当我们学到后面也能知道:一个模块(功能)中,也有且只有一个main方法
// public static void main(String[]args) {
int x = 5;
while(x > 1) {
x = x - 1;
if(x < 3) {
System.out.println("small x");
}
}
// }
}
P.22
JavaCross7.0https://blog.csdn.net/u012814856/article/details/78852471?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_utm_term~default-0.pc_relevant_default&spm=1001.2101.3001.4242.1&utm_relevant_index=3
P.23
y = x - y; | 00 11 21 32 42 |
y = y + x; | 00 11 23 36 410 |
y = y + 2; if(y > 4){ y = y - 2; } | 02 14 25 36 47 |
x = x + 1; y = y + x; | 11 34 59 |
if(y<5){ x = x + 1; if(y < 3){ x = x -1; } } y = y + 2; | 02 14 36 48 |
P.24
public class PoolPuzzleOne {
public static void main(String[] args) {
int x = 0;
while (x < 4) {
System.out.print("a");
if (x < 1) {
System.out.print(" ");
}
System.out.print("n");
if (x > 1) {
System.out.print(" oyster");
x = x + 2;
}
if (x == 1) {
System.out.print("noys");
}
if (x < 1) {
System.out.print("oise");
}
System.out.println("");
x = x + 1;
}
}
}