JAVA

Sunday, November 20, 2005

Homework 10-31 Lab (1) String Comparison

public class dog
{ public static void main(String args[])
{ String s1="I come from CYCU.";
String s2="I come from cycu.";
if(s1.equals(s2))
System.out.println("They are the same!!");
else
System.out.println("They are different!!");
}
}

http://home.pchome.com.tw/club/savvygirl/dog.JPG
1 ' ==' 只能用在基本的data type而在這裡string產生出來已經是一個object所以要用.equals來看此object 裡面的內容是否相等
2是指有大小寫之分所以如本題是不成立
3是指沒有大小寫之區別

0 Comments:

Post a Comment

<< Home