这是我乱写的一段代码,不为什么.就是锻炼打代码..请问包含equals的那段代码有什么问题.为什么它会抛出异常呢.
public class CeShi{
int i=20;
public static String s1=new String("123");
public static String s2="123";
public static String s3=new String("123");
public int method(int x){
for(x=0;x<110;x++)
System.out.println(x);
return x;
}
public static void main(String[] args){
CeShi s=new CeShi();
System.out.println(s.method(0));
System.out.println(s.i);
System.out.println(s1==s2);
System.out.println(s2==s3);
System.out.println(s1==s3);
try{
System.out.println(s1.equals(s3));
}
catch(Exception e)
{System.out.println("这段代码有异常");}
}
}
我没有什么积分.而且是新人.大家帮帮忙好吗?我思考了很久也不懂.刚学比较菜..但是我很渴望弄明白这个道理..谢谢各位了!
public class CeShi{
int i=20;
public static String s1=new String("123");
public static String s2="123";
public static String s3=new String("123");
public int method(int x){
for(x=0;x<110;x++)
System.out.println(x);
return x;
}
public static void main(String[] args){
CeShi s=new CeShi();
System.out.println(s.method(0));
System.out.println(s.i);
System.out.println(s1==s2);
System.out.println(s2==s3);
System.out.println(s1==s3);
try{
System.out.println(s1.equals(s3));
}
catch(Exception e)
{System.out.println("这段代码有异常");}
}
}
我没有什么积分.而且是新人.大家帮帮忙好吗?我思考了很久也不懂.刚学比较菜..但是我很渴望弄明白这个道理..谢谢各位了!
解决方案 »
- 在这里向大家请教一个问题,怎么准备面试+笔试
- 请问什么原因HTTP Status 404 - /webproject/RegServlet.aspx
- "事务"和"同步"之间究竟有什么不同,有什么联系
- 请高手指教关于字符格式转换过程中乱码问题,byte,char,string之间的相互转换。
- 500分求在Servlet里调用定时器的源码!!!
- 新手练习cs项目取不到mysql的内容 求大神解答
- 如何从外界强制停止Thread类并释放它的资源?
- 我怎么把str=“中国人民”; 字符串进行向右移动2位的运算?
- 问个问题,SCJP的考试,在GUI部分大概考什么内容?
- 多线程 wait用法
- 请问JAVA中有内存泄漏么?为什么?
- 请推荐一本好的EJB教材。
结果:0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
20
false
false
false
true
public static String s3=new String("123");
我想原因应该是这个
你如果放S2就应该没问题!
int i=20;
public static String s1=new String("123");
public static String s2="123";
public static String s3=new String("123");
public int method(int x){
for(x=0;x <3;x++)
System.out.println(x);
return x;
}
public static void main(String[] args){
CeShi s=new CeShi();
System.out.println(s.method(0));
System.out.println(s.i);
System.out.println(s1==s2);
System.out.println(s2==s3);
System.out.println(s1==s3);
System.out.println(s1.equals(s3));
}
} 这是去掉try catch之后的,可以正常运行