indexofexample.java

来自「java 完全探索的随书源码」· Java 代码 · 共 46 行

JAVA
46
字号
public class IndexOfExample{  // Default Constructor  public IndexOfExample()  {    super();  }  // Method that actually performs the search  public int doSearch( String str, String subStr )  {    return str.indexOf( subStr );  }  // Main Method  public static void main( String[] args )  {    if ( args.length != 2 )    {      System.out.println( "Usage: java IndexOfExample <String> <Substring>" );      System.exit( 0 );    }    // Create an instance of the example    IndexOfExample example = new IndexOfExample();    // Get the strings passed in from the command line    String str = args[0];    String subStr = args[1];    // Inform the user what is going on    System.out.println( "Searching string: " + str + " for: " + subStr );    // perform the search    int index = example.doSearch( str, subStr );    // check the result    if ( index != -1 )    {      System.out.println( "Found the substring at position " + index );    }    else    {      System.out.println( "Did not find the substring" );    }  }}

⌨️ 快捷键说明

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