一个java程序,麻烦大家帮忙看看,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/05/12 16:18:57
1) Assume the definitions:
String s1 = “Test1”;
String s2 = “test1”;
String s3 = “Test1”;
String s4 = “Test2”;
String s5 = s1;

What will be the results of the following expressions?
a) s1.equals (s2);
b) s1.equals (s3);
c) s1.equals IgnoreCase(s2);
d) s1 == s3;
e) s1 == s5;
f) s1.compareTo (s2);
g) s1.compareTo (s4);
h) s1.regionMatches (1, s2, 1, 3);
i) s1.regionMatches (true, 1, s2, 1, 3);
j) s1.startsWith (“Te”);
k) s4.endsWith (“1”);

2) Assume the definition:
String s1 = “ The first string “;
What will be the results of the following expressions?

a) s1.indexOf (“st”);
b) s1.indexOf (“st”, 14);
c) s1.lastIndexOf (“st”);
d) s1.indexOf (‘i’);
e) s1.replace(‘s’, ‘S’);
f) s1.toUpperCase ();
g) s1.trim ();

3) Assume the definition:
StringBuffer b1 = new StringBuffer (“1234567890“);
String s1;

What will be

这不是程序,是试题,像是SJCP的考试题
=====
等……我看看再补充
1)
===========================
public class Test1{
public static void main(String[] args){
String s1 = "Test1";
String s2 = "test1";
String s3 = "Test1";
String s4 = "Test2";
String s5 = s1;

System.out.println("a) "+ s1.equals (s2));
System.out.println("b) "+ s1.equals (s3));
System.out.println("c) "+ s1.equalsIgnoreCase(s2));
System.out.println("d) "+ (s1 == s3));
System.out.println("e) "+ (s1 == s5));
System.out.println("f) "+ s1.compareTo (s2));
System.out.println("g) "+ s1.compareTo (s4));
System.out.println("h) "+ s1.regionMatches (1, s2, 1, 3));
System.out.println("i) "+ s1.regionMatches (true, 1, s2, 1, 3));
System.out.println("j) "+ s1.startsWith ("Te"