本帖最后由 月之吟 于 2015-2-19 12:57 编辑
No 11
这个失误了:lol:public class No11 {
public static void main(String[] aegs) {
System.out.println("第8个人的年龄为" + age(8));
}
static int age(int i) {
if (i == 1) {
return 10;
} else {
return age(i - 1) + 2;
}
}
}
No 12
在微秒那行的24后加'L'public class No12 {
public static void main(String[] args) {
final long PER_DAY_US = 24L * 60 * 60 * 1000 * 1000;
final long PER_DAY_MS = 24 * 60 * 60 * 1000;
System.out.println(PER_DAY_US / PER_DAY_MS);
}
}
No 13
将 j++ 改为 ++j 。public class No13 {
public static void main(String[] args) {
int j = 0;
for (int i = 0; i < 100; i++) {
j = ++j;
}
System.out.println("j = " + j);
}
}
No 14
将 for 循环中添加 i 等于 end 时用 break 跳出的语句,并将for中的i<=end去掉。应该算对吧……public class No14 {
private final static int end = Integer.MAX_VALUE;
private final static int start = Integer.MAX_VALUE - 100;
public static void main(String[] args) {
int count = 0;
for (int i = start;; i++) {
count++;
if(i==end){
break;
}
}
System.out.println(" count = " + count);
}
}
No 18
将所有case最后都加上break,将StringBuffer()中的单引号都改成双引号。import java.util.Random;
public class No18 {
private static Random rdm = new Random();
public static void main(String[] args) {
StringBuffer word = null;
switch (rdm.nextInt(3)) {
case 1:
word = new StringBuffer("P");
break;
case 2:
word = new StringBuffer("G");
break;
default:
word = new StringBuffer("M");
}
word.append('a');
word.append('i');
word.append('n');
System.out.println("word = " + word);
}
}
目前我的水平就只会这些了……
重在参与,继续学习进步
|