习题答案
第1章习题答案
java入门课件一、选择题
1. A 2. D 3. C 4. B 5. B 6. D
二、编程题
public class Test { public static void main(String[] args) { System.out.println("小绿"); println("16"); System.out.println("男"); System.out.println("440105************"); } } |
第2章习题答案
一、选择题
1. A 2. A 3. C 4. D 5. D
二、填空题
1. 0 2. parseInt 3. 10
4. for(int i=3;i>=0;i--){ System.out.print(array[i]);}
5. for (int i = 0; i < arry.length; i++) {System.out.print(arry[i]);}
三、编程题
1.
public class Test { public static void main(String[] args) { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + "*" + i + "=" + (i * j) + "\t"); } System.out.println(); } System.out.println("==========================="); for (int i = 9; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j + "*" + i + "=" + (i * j) + "\t"); } System.out.println(); } } } |
2.
public class Test { public static void main(String[] args) { int cock; int hen; int chicken; for (cock = 0; cock <= 20; cock++) { for (hen = 0; hen <= 33; hen++) { for (chicken = 0; chicken <= 99; chicken = chicken + 3) { if (cock + hen + chicken == 100 && cock * 5 + hen * 3 + chicken / 3 == 100) { System.out.println("公鸡:" + cock); System.out.println("母鸡:" + hen); System.out.println("小鸡:" + chicken); System.out.println(); } } } } } } |
3.
public class Test { public static void main(String[] args) { int x = 0, y = 0, z = 0; int num=0; for (int i = 100; i < 999; i++) { x = i / 100; y = (i % 100) / 10; z = (i % 100) % 10; if (x * x * x + y * y * y + z * z * z == i) { num++; System.out.println("第"+num+"个水仙数是:"+i); } } } } |
4.
public class Test { public static void main(String[] args) { int value1 = 1; int value2 = 1; int value3; System.out.print(value1 + " "); System.out.print(value2 + " "); for (int num = 3; num <= 20; num++) { value3 = value1 + value2; System.out.print(value3 + " "); value1 = value2; value2 = value3; } } } |
5.
public class Test { public static void main(String[] args) { int[] array = new int[] { 1, 3, 33, 13, 63, 53, 23, 73 }; int max = array[0]; int min = array[0]; for (int i = 1; i < array.length; i++) { if (array[i] > max) { max = array[i]; } if (array[i] < min) { min = array[i]; } } System.out.println("数组中最大值为:" + max); System.out.println("数组中最小值为:" + min); } } |
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论