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

Ask the user to enter a phrase, sentence or paragraph. Read it in as a String, t

ID: 3608819 • Letter: A

Question

Ask the user to enter a phrase, sentence or paragraph. Read it in as a String, then report back to the user by displayingthe following:

Make sure you never modify the original string: Youradjustments should either be made to copies of the original orshould simply be sent directly to the screen, never copied back tothe original string the user entered. Also, be sure that youdon't assume that only letters are entered. The user mightenter numerals or special symbols, and these should not be countedas either vowels or consonants.

Explanation / Answer


import java.io.*;
public class StringModify { public static void main(String[] args) { try { BufferedReader in = new BufferedReader(newInputStreamReader(System.in)); String s1 = ""; int vCount = 0, cCount = 0; System.out.println("Enter a phrase, sentence, or paragraph:"); s1 = in.readLine(); System.out.println(" " + s1.toUpperCase()); System.out.println(s1.toLowerCase()); for(int i = 0; i < s1.length(); i++) { if(Character.isLetter(s1.charAt(i))) { if(Character.toUpperCase(s1.charAt(i)) == 'A' ||Character.toUpperCase(s1.charAt(i)) == 'E' ||Character.toUpperCase(s1.charAt(i)) == 'I' || Character.toUpperCase(s1.charAt(i)) == 'O' ||Character.toUpperCase(s1.charAt(i)) == 'U') { vCount++; } else cCount++; } } System.out.println(" Number of vowels: " + vCount); System.out.println("Number of consonants: " + cCount); for(int i = s1.length()-1; i >= 0; i--) System.out.print(s1.charAt(i)); } catch(Exception e) { e.printStackTrace(); } } } import java.io.*;
public class StringModify { public static void main(String[] args) { try { BufferedReader in = new BufferedReader(newInputStreamReader(System.in)); String s1 = ""; int vCount = 0, cCount = 0; System.out.println("Enter a phrase, sentence, or paragraph:"); s1 = in.readLine(); System.out.println(" " + s1.toUpperCase()); System.out.println(s1.toLowerCase()); for(int i = 0; i < s1.length(); i++) { if(Character.isLetter(s1.charAt(i))) { if(Character.toUpperCase(s1.charAt(i)) == 'A' ||Character.toUpperCase(s1.charAt(i)) == 'E' ||Character.toUpperCase(s1.charAt(i)) == 'I' || Character.toUpperCase(s1.charAt(i)) == 'O' ||Character.toUpperCase(s1.charAt(i)) == 'U') { vCount++; } else cCount++; } } System.out.println(" Number of vowels: " + vCount); System.out.println("Number of consonants: " + cCount); for(int i = s1.length()-1; i >= 0; i--) System.out.print(s1.charAt(i)); } catch(Exception e) { e.printStackTrace(); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote