1.按模板要求,將【代碼1】~【代碼9】替換爲Java程序代碼。
class StringExample<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
{
public static void main(String args[ ])
{
String s1=new String("you are a student"),
s2=new String("how are you");
if (s1==s2) // 判斷s1與s2是否相同
{
System.out.println("s1與s2相同");
}
else
{
System.out.println("s1與s2不相同");
}
String s3=new String("22030219851022024");
if (s3.substring(0,6)=="220302") // 判斷s3的前綴是否是“<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />220302”
{
System.out.println("吉林省的身份證");
}
String s4=new String("你"),
s5=new String("我");
if(s4.compareTo("你")>s5.compareTo("我")) // 按着字典序s4大於s5的表達式
{
System.out.println("按字典序s4大於s5");
}
else
{
System.out.println("按字典序s4小於s5");
}
int position=0;
String path="c://java//jsp//A.java";
position=path.lastIndexOf("//"); // 獲取path中最後出現目錄分隔符號的位置
System.out.println("c://java//jsp//A.java中最後出現//的位置:"+position);
String fileName=path.substring(15, 21); // 獲取path中“A.java”子字符串
System.out.println("c://java//jsp//A.java中含有的文件名:"+fileName);
String s6=new String("100"),
s7=new String("123.678");
int n1=Integer.parseInt(s6); // 將s6轉化成int型數據
double n2=Double.parseDouble(s7); // 將s7轉化成double型數據
double n=n1+n2;
System.out.println(n);
String s8=new String("ABCDEF");
char a[ ]= s8.toCharArray(); // 將s8存放到數組a中
for(int i=a.length-1;i>=0;i--)
{
System.out.printf("%3c",a[i]);
}
}
}