📄 stringcompareexample.java
字号:
public class StringCompareExample{ // Default Constructor public StringCompareExample() { super(); } // Method that actually performs the comparison public int compareStrings( String str1, String str2 ) { return str1.compareTo( str2 ); } // Main Method public static void main( String[] args ) { if ( args.length != 2 ) { System.out.println( "Usage: java StringCompareExample <String1> <String2>" ); System.exit( 0 ); } // Create an instance of the example StringCompareExample example = new StringCompareExample(); // Get the strings passed in from the command line String str1 = args[0]; String str2 = args[1]; // Inform the user what is going on System.out.println( "Comparing string: '" + str1 + "' with: '" + str2 + "'"); // perform the comparison int result = example.compareStrings( str1, str2 ); // check the result for a negative if ( result < 0 ) { System.out.println( "String 1 is less than String 2" ); } else if ( result > 0 ) { System.out.println( "String 1 is greater than String 2" ); } else { System.out.println( "String 1 and String 2 are equal" ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -