java高手进来~!~!帮做两个题,马上要交了,

来源:百度知道 编辑:UC知道 时间:2024/05/29 10:44:21
第二题:阅读程序,写出执行结果。(20分)
1.(6分)
public class Tester1{
public static void main(String[] args){
for(int i=1;i<=10;i++)
if(i%3==0)System.out.println(i);
}
}
2.(4分)
public class Tester2{
int i=0;
void p(){
i++;
if(i%2==0)System.out.println(i);
return this;
}
public static void main(String[] args){
Tester2 t = new Tester2();
t.p().p().p().p().p();
}
}
3.(4分)
public class Tester3{
public static void main(String args[]){
int i=2,j=3,k=4;
System.out.println(""+i+j+k);
System.out.println(i+j+k+"");
}
}
4. (6分)
public class Tester4{
static int i=1;
static int m(){
return i++;
}
public static void main(String[] args){
System.out.println(Test4.m());
Tester4 t1 = new Tester4();
System.out.println(t1.m());
Tester4 t2 = new Tester4();
System.out.pr

1.答案:
3
6
9

2.编译有问题,应该将p定义为 Tester2 p()
答案:
2
4

3.答案:
234
9

4.编译有问题,应修改为System.out.println(Tester4.m());
答案:
1
2
3

1) 3,6,9
2) 2,4
3) 234,234
4) 1,1,2

朋友你可以不妨就把它运行哈,看,这也是个好方法哦,

1题:3,6,9
2题:2,4
3题:234,9
4题:1,2,3

没问题都运行过了