Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Converts a string to lowercase, and displays the string\'s length as well as a c

ID: 3832304 • Letter: C

Question

Converts a string to lowercase, and displays the string's length as well as a count of letters public class Debugseven public static void main (String args) string astring HELP I need to get 37 things DONE today int numLetters 0; int stringLength String. length; System. out.println In all lowercase, the sentence is: for (int i 0; i length i++) char ch Character toLowerCase (astring.charAt (length) System. out. print (ch): if (Character Letter numLetters++; System. out.println System.out.println The number of CHARACTERS in the string is string Length) System. out.println The number of LETTERS is string Length)

Explanation / Answer

DebugSeven4.java


public class DebugSeven4 {

  
   public static void main(String[] args) {
       String aString = "HELP! I need to get 37 things DONE today!!";
       int numLetters = 0;
       int stringLength = aString.length();
       System.out.println("In all lowercase, the sentence is: ");
           for(int i=0; i<stringLength; i++){
               char ch = Character.toLowerCase(aString.charAt(i));
               System.out.print(ch);
               if(Character.isLetter(ch))
                   numLetters++;
           }
           System.out.println();
           System.out.println("The number of CHARACTERS in the string is: "+stringLength);
           System.out.println("The number of LETTERS is "+numLetters);
   }

}

Output:

In all lowercase, the sentence is:
help! i need to get 37 things done today!!
The number of CHARACTERS in the string is: 42
The number of LETTERS is 29

DebugSeven3.java


public class DebugSeven3 {
   public static void main(String[] args) {
       String quote = "Honesty is the first character in the book os wisdom. - Thomas Jefferson";
       System.out.println("indexOf('f') is: "+quote.indexOf('f') );
       System.out.println("indexOf('x') is: "+quote.indexOf('x') );
       System.out.println("charAt(5) is: "+quote.charAt(5));
       System.out.println("endsWith("daughter") is: "+quote.endsWith("daughter"));
       System.out.println("endsWith("son") is: "+quote.endsWith("son"));
       System.out.println("replace('e', 'E') is: "+quote.replace('e','E'));
   }
}

Output:

indexOf('f') is: 15
indexOf('x') is: -1
charAt(5) is: t
endsWith("daughter") is: false
endsWith("son") is: true
replace('e', 'E') is: HonEsty is thE first charactEr in thE book os wisdom. - Thomas JEffErson