📄 substringexample.java
字号:
public class SubstringExample{ // Default Constructor public SubstringExample() { super(); } // Method that actually performs the extraction public String extractSubstring( String str1, int beginIndex, int endIndex ) { return str1.substring( beginIndex, endIndex ); } // Main Method public static void main( String[] args ) { if ( args.length != 3 ) { System.out.println( "Usage: java StringCompareExample <String1> <String2>" ); System.exit( 0 ); } String str = args[0]; String beginIndexStr = args[1]; String endIndexStr = args[2]; int beginIndex = 0; int endIndex = 0; // Make sure the arguments are valid try { beginIndex = Integer.parseInt( beginIndexStr ); endIndex = Integer.parseInt( endIndexStr ); } catch( NumberFormatException ex ) { System.out.println( "The arguments are invalid" ); } // Create an instance of the example SubstringExample example = new SubstringExample(); // Get the strings passed in from the command line // Inform the user what is going on System.out.println( "Extrating from string: '" + str + "' starting at: " + beginIndex + " endIndex: " + endIndex ); // perform the comparison String newSubstring = example.extractSubstring( str, beginIndex, endIndex ); System.out.println( "Substring: " + newSubstring ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -