作業答案

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)  // 判斷s1s2是否相同

         {

            System.out.println("s1s2相同");

         }

        else

         {

           System.out.println("s1s2不相同"); 

         }

         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]);

          }

    }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章