⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringstartend.java

📁 我在学习JAVA的讲义
💻 JAVA
字号:
import javax.swing.*;

public class StringStartEnd {
   public static void main( String args[] )
   {
      String strings[] = { "started", "starting", 
                           "ended", "ending" };
      String output = "";

      // Test method startsWith
      for ( int i = 0; i < strings.length; i++ )
         if ( strings[ i ].startsWith( "st" ) )
            output += "\"" + strings[ i ] +
                      "\" starts with \"st\"\n";

      output += "\n";

      // Test method startsWith starting from position
      // 2 of the string
      for ( int i = 0; i < strings.length; i++ )
         if ( strings[ i ].startsWith( "art", 2 ) ) 
            output += 
               "\"" + strings[ i ] +
               "\" starts with \"art\" at position 2\n";

      output += "\n";

      // Test method endsWith
      for ( int i = 0; i < strings.length; i++ )
         if ( strings[ i ].endsWith( "ed" ) )
            output += "\"" + strings[ i ] +
                      "\" ends with \"ed\"\n";

      JOptionPane.showMessageDialog( null, output,
         "Demonstrating String Class Comparisons",
         JOptionPane.INFORMATION_MESSAGE );

      System.exit( 0 );
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -