沉默奔跑者

          記錄學(xué)習(xí)軌跡
          隨筆 - 1, 文章 - 2, 評(píng)論 - 5, 引用 - 0
          數(shù)據(jù)加載中……

          字符串1

          import javax.swing.*;

          public class StringTest2 {
              
          public static void main(String args[]){
                  String s1,s2,s3,s4,output;
                  
                  s1
          =new String ("good morning");
                  s2
          =new String ("John");
                  s3
          =new String("How are you");
                  s4
          =new String("   how are you");
                  
                  output
          ="s1="+s1+"\ns2="+s2+"\ns3="+s3+"\ns4"+s4+"\n\n";
                  
                  
          if(s1.equals("hello"))
              output
          +="s1 equals\"hello\"\n";
                  
          else
                  output
          +="s1 dose not equal\"hello\"\n";
                  
                  
          if (s3.equalsIgnoreCase(s4))
                  output
          +="s3 equals s4\n";
                  
          else
                  output
          +="s3 dose not equal s4\n";
                  
                  
          if(s3.regionMatches(0,s4,0,5))
                  output
          +="First 5 characters of s3 and s4 match\n";
                  
          else
                  output
          +="First 5 characters of s3 and s4 do not match\n";
                  
                      
          if(s3.regionMatches(true,0,s4,0,5))
                  output
          +="First 5 characters of s3 and s4 match\n";
                  
          else
                  output
          +="First 5 characters of s3 and s4 do not match\n";
              
                  output
          +="s1與s4連接起來(lái)是:"+s1.concat(s4)+"\n";
                  
                  output
          +="the first\"day\"of s4 is :"+s4.indexOf("you")+"\n";
                  output
          +="the last\"day\"of s4 is :"+s4.lastIndexOf("we");
                  
                  JOptionPane.showMessageDialog(
          null,output,"Demonstring String Class CONstructors",JOptionPane.INFORMATION_MESSAGE);
                  System.exit(
          0);
              }

              
          }

          //p133

          posted on 2008-03-10 12:25 沉默奔跑者 閱讀(265) 評(píng)論(5)  編輯  收藏

          評(píng)論

          # re: 字符串1  回復(fù)  更多評(píng)論   

          import javax.swing.*;
          public class InputTest {
              
          public static void main(String args[]){
                  String name
          =JOptionPane.showInputDialog("What is your name?");
                  String input
          =JOptionPane.showInputDialog("How old are you?");
                  
          int age=Integer.parseInt(input);
                  System.out.println(
          "Hello,"+name+".Next year,you'll be"+(age+1));
              System.exit(
          0);
              }

              
          }

          2008-03-11 09:14 | 沉默奔跑者

          # re: 字符串1  回復(fù)  更多評(píng)論   

          class Const {
          public static void main(String[] args){
             
          char chars1[]={'t','e','s','t'};
             
          char chars2[]={'t','e','s','t','1'};
             String s1
          =new String(chars1);
             String s2
          =new String(chars2);
             System.out.println(
          "Value of String s1 is :"+s1);
             System.out.println(
          "Value of String s2 is:"+s2);
             System.out.println(
          "他們都是字符串\"test\"!");
          }

          }

          2008-03-11 09:15 | 沉默奔跑者

          # re: 字符串1  回復(fù)  更多評(píng)論   

          class ExampleStringBuffer {
          public static void main(String[] buf){
          StringBuffer sb
          =new StringBuffer("test");
          System.out.println(
          "buffer="+sb);
          System.out.println(
          "length="+sb.length());
          System.out.println(
          "capacity="+sb.capacity());
          }

          }

          2008-03-11 09:19 | 沉默奔跑者

          # re: 字符串1  回復(fù)  更多評(píng)論   

          public  class StringTest1 {
              
          public  static void main(String args[]){
                  
          char c1[]={'t','o','m','i','s','a','b','o','y'};
                  String s1
          ="good morning";
                  String s2
          =new String();
                  String s3
          =new String(c1);
                  String s4
          =new String(c1,6,3);
                  
                  System.out.println(
          "s1 is :"+s1);
                  System.out.println(
          "s2 is:"+s2);
                  System.out.println(
          "s3 is:"+s3);
                  System.out.println(
          "s4 is:"+s4);
              }

          }

          2008-03-11 09:20 | 沉默奔跑者

          # re: 字符串1  回復(fù)  更多評(píng)論   


          import javax.swing.*;

          public class StringTest2 {
              
          public static void main(String args[]){
                  String s1,s2,s3,s4,output;
                  
                  s1
          =new String ("good morning");
                  s2
          =new String ("John");
                  s3
          =new String("How are you");
                  s4
          =new String("   how are you");
                  
                  output
          ="s1="+s1+"\ns2="+s2+"\ns3="+s3+"\ns4"+s4+"\n\n";
                  
                  
          if(s1.equals("hello"))
              output
          +="s1 equals\"hello\"\n";
                  
          else
                  output
          +="s1 dose not equal\"hello\"\n";
                  
                  
          if (s3.equalsIgnoreCase(s4))
                  output
          +="s3 equals s4\n";
                  
          else
                  output
          +="s3 dose not equal s4\n";
                  
                  
          if(s3.regionMatches(0,s4,0,5))
                  output
          +="First 5 characters of s3 and s4 match\n";
                  
          else
                  output
          +="First 5 characters of s3 and s4 do not match\n";
                  
                      
          if(s3.regionMatches(true,0,s4,0,5))
                  output
          +="First 5 characters of s3 and s4 match\n";
                  
          else
                  output
          +="First 5 characters of s3 and s4 do not match\n";
              
                  output
          +="s1與s4連接起來(lái)是:"+s1.concat(s4)+"\n";
                  
                  output
          +="the first\"day\"of s4 is :"+s4.indexOf("you")+"\n";
                  output
          +="the last\"day\"of s4 is :"+s4.lastIndexOf("we");
                  
                  JOptionPane.showMessageDialog(
          null,output,"Demonstring String Class CONstructors",JOptionPane.INFORMATION_MESSAGE);
                  System.exit(
          0);
              }

              
          }

          //p133
          2008-03-11 09:22 | 沉默奔跑者

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 大足县| 治多县| 民权县| 修武县| 成都市| 贵溪市| 门源| 三江| 三亚市| 徐水县| 阿荣旗| 正阳县| 孟津县| 邵武市| 丹阳市| 中超| 山阳县| 三原县| 廉江市| 汉寿县| 平邑县| 广德县| 潞城市| 青冈县| 古交市| 上林县| 滦南县| 易门县| 峡江县| 耿马| 班玛县| 安仁县| 广灵县| 贵州省| 防城港市| 淳安县| 临沂市| 宁明县| 崇左市| 洛扎县| 雅江县|