📄 indexofexample.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -