public class App { public static String convertToUpperCase(String str) { return result; } public static String convertToLowerCase(String str) { return result; } public static int lengthOfString(String str){ return result; } public static int indexOfWord(String str, String word){ return result; } public static String removeFirstCharOccurrence(String str, char c){ return result; } public static String replaceString(String str, String w1, String w2){ return result; } public static int compareStrings(String s1, String s2){ return result; } public static void main( String[] args ) { String str = ""; System.out.println( "Welcome to Lab 3" ); Scanner keyboard = new Scanner(System.in); System.out.println( "Enter a string then press enter:" ); str = keyboard.nextLine(); System.out.println("The string in Upper case: " + convertToUpperCase(str)); System.out.println("The string in Lower case: " + convertToLowerCase(str) ); System.out.println("The length of the string is: " +lengthOfString(str)); System.out.println( "Enter a word to search for: " ); String word1 = keyboard.next(); keyboard.nextLine(); System.out.println("Index of "+ word1+" is: "+indexOfWord(str,word1) ); System.out.println( "Enter another word to replace it with the earlier word :" ); String word2 = keyboard.nextLine(); System.out.println("After replacement: " + replaceString(str, word1, word2)); System.out.println("Enter a letter to remove from the original string: "); char c = keyboard.next().charAt(0); keyboard.nextLine(); System.out.println("The string after removing first occurrence of '"+ c + "' is: "+ removeFirstCharOccurrence(str,c)); System.out.println("Enter the first String: "); String s1 = keyboard.nextLine(); System.out.println("Enter the second String: "); String s2 = keyboard.nextLine(); if (compareStrings(s1,s2) < 0){ System.out.println("The string: "+s1+" ,comes before "+s2); } else if (compareStrings(s1, s2) > 0){ System.out.println("The string: "+s2+" ,comes before "+s1); } else{ System.out.println("The string: "+s2+" and "+s1+" are equal"); } keyboard.close(); } } 1. Convert all the characters in the string to upper cases 2. Convert all the characters in the string to lower cases 3. Find number of characters in the string 4. Find/search for a word within the string 5. Replace a word within the string with a new word 6. Remove a letter from the string 7. Compare two strings alphabetically Tips: you might use the following methods: • length ( ) • indexOf ( ) • toUpperCase( ) • toLowerCase( ) • substring ( ) • compareTo ( ) Grading and Submission Your grade will be based on your effort on trying to complete the exercise.
public class App
{
public static String convertToUpperCase(String str) {
return result;
}
public static String convertToLowerCase(String str) {
return result;
}
public static int lengthOfString(String str){
return result;
}
public static int indexOfWord(String str, String word){
return result;
}
public static String removeFirstCharOccurrence(String str, char c){
return result;
}
public static String replaceString(String str, String w1, String w2){
return result;
}
public static int compareStrings(String s1, String s2){
return result;
}
public static void main( String[] args )
{
String str = "";
System.out.println( "Welcome to Lab 3" );
Scanner keyboard = new Scanner(System.in);
System.out.println( "Enter a string then press enter:" );
str = keyboard.nextLine();
System.out.println("The string in Upper case: " + convertToUpperCase(str));
System.out.println("The string in Lower case: " + convertToLowerCase(str) );
System.out.println("The length of the string is: " +lengthOfString(str));
System.out.println( "Enter a word to search for: " );
String word1 = keyboard.next();
keyboard.nextLine();
System.out.println("Index of "+ word1+" is: "+indexOfWord(str,word1) );
System.out.println( "Enter another word to replace it with the earlier word :" );
String word2 = keyboard.nextLine();
System.out.println("After replacement: " + replaceString(str, word1, word2));
System.out.println("Enter a letter to remove from the original string: ");
char c = keyboard.next().charAt(0);
keyboard.nextLine();
System.out.println("The string after removing first occurrence of '"+ c + "' is: "+ removeFirstCharOccurrence(str,c));
System.out.println("Enter the first String: ");
String s1 = keyboard.nextLine();
System.out.println("Enter the second String: ");
String s2 = keyboard.nextLine();
if (compareStrings(s1,s2) < 0){
System.out.println("The string: "+s1+" ,comes before "+s2);
}
else if (compareStrings(s1, s2) > 0){
System.out.println("The string: "+s2+" ,comes before "+s1);
}
else{
System.out.println("The string: "+s2+" and "+s1+" are equal");
}
keyboard.close();
}
}
1. Convert all the characters in the string to upper cases 2. Convert all the characters in the string to lower cases 3. Find number of characters in the string 4. Find/search for a word within the string 5. Replace a word within the string with a new word 6. Remove a letter from the string 7. Compare two strings alphabetically Tips: you might use the following methods:
• length ( )
• indexOf ( )
• toUpperCase( )
• toLowerCase( )
• substring ( )
• compareTo ( )
Grading and Submission
Your grade will be based on your effort on trying to complete the exercise.
Step by step
Solved in 3 steps with 1 images