import javax.swing.*;
public class oo {
public static void main( String args[] )
{
String letters = "abcdefghijklmabcdefghijklm";
String output = "'c' is located at index " + letters.indexOf( 'c' );
output += "'a' is located at index " + letters.indexOf( 'a', 1 );
output += "'$' is located at index " + letters.indexOf( '$' );
output += "Last 'c' is located at index " +
letters.lastIndexOf( 'c' );
output += "Last 'a' is located at index " +
letters.lastIndexOf( 'a', 25 );
output += "Last '$' is located at index " +
letters.lastIndexOf( '$' );
output += ""def" is located at index " +
letters.indexOf( "def" );
output += ""def" is located at index " +
letters.indexOf( "def", 7 );
output += ""hello" is located at index " +
letters.indexOf( "hello" );
output += "Last "def" is located at index " +
letters.lastIndexOf( "def" );
output += "Last "def" is located at index " +
letters.lastIndexOf( "def", 25 );
output += "Last "hello" is located at index " +
letters.lastIndexOf( "hello" );
JOptionPane.showMessageDialog( null, output,
"String searching methods", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}
留言列表