Publicité

case b prompt the user to enter a word.pdf

1 Apr 2023
case b                     prompt the user to enter a word.pdf
case b                     prompt the user to enter a word.pdf
case b                     prompt the user to enter a word.pdf
case b                     prompt the user to enter a word.pdf
Prochain SlideShare
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Chargement dans ... 3
1 sur 4
Publicité

Contenu connexe

Plus de sales88(20)

Publicité

case b prompt the user to enter a word.pdf

  1. case 'b' : // prompt the user to enter a word System.out.print("nEnter a word: "); // String words = sc.next(); String word = sc.next(); // count the number of vowels and how many of each vowel was found int totalVowels = 0; int aCount = 0; int eCount = 0; int iCount = 0; int oCount = 0; int uCount = 0; int yCount = 0; for (int i = 0; i < word.toLowerCase().length(); i++) { char vowel = word.toLowerCase().charAt(i); if (vowel == 'a') { totalVowels++; aCount++; } else if ( vowel == 'e') { totalVowels++; eCount++; } else if ( vowel == 'i') { totalVowels++; iCount++; } else if ( vowel == 'o') { totalVowels++; oCount++; } else if (vowel == 'u') { totalVowels++;
  2. uCount++; } else if ( vowel == 'y') { totalVowels++; yCount++; } } // display the results if (totalVowels == 0) { System.out.println("n" + word +" contains no vowels"); } else { System.out.printf("n%-25s %d nn" , "Total Vowels: " , totalVowels); if (aCount != 0) { System.out.printf("%-25s %d n" , "A: " , aCount); } if (eCount != 0) { System.out.printf("%-25s %d n" , "E: " , eCount); } if (iCount != 0) { System.out.printf("%-25s %d n" , "I: " , iCount); } if (oCount != 0) { System.out.printf("%-25s %d n" , "O: " , oCount); } if (uCount != 0) { System.out.printf("%-25s %d n" , "U: " , uCount); } if (yCount != 0) { System.out.printf("%-25s %d n" , "Y: " , yCount); } } break; // --------------------------------------------------------------------------------------- case 'c' : System.out.print("n");
  3. // number of spaces in the design int space = 5; // loop through each row for (int i = 1; i <= space; i++) { // print spaces before asterisks for (int j = 1; j <= space - i; j++) { System.out.print(" "); } for (int k = 1; k <= i; k++) { // print asterisks System.out.print("*"); } System.out.println(); } break; // --------------------------------------------------------------------------------------- case 'd' : // ending the program System.out.println("nTerminated"); break; // --------------------------------------------------------------------------------------- default : // error message System.out.println("n<< ERROR !! >>n<< Please select the correct option >>"); }
  4. // --------------------------------------------------------------------------------------- System.out.print("n---------------------------------------------------------------------------------- -----"); } } } CAN YOU CHECK THIS CODE. ITS IN JAVA. PURPOSE This assignment will enhance your ability to utilize loops in a computer program. By the end of this assignment, you should feel comfortable working with while loops, for loops, and nested loops. PROBLEM Write a program that repeatedly displays a menu to the screen until the user exits the program. The menu options are listed below a) Statistics Prompt the user to enter an integer called n. Then repeatedly prompt the user to enter n values that are of type double. Display the average, maximum, minimum, and middle value. Assume the middle value is the ((n+1)/2)th value entered. b) Vowel count Prompt the user to enter a word and display the total number of vowels in that word. Also, display how many of each vowel was found. If no vowels are found, display an appropriate message to the user. Assume vowels are A, E, I, O, U, Y (case insensitive). c) Display asterisk design Use a nested for loop to display the asterisk design shown in the sample input/output. d) Exit The program should terminate when the user selects this option ** If the user a selects an invalid menu option, an error message should display. a) Statistics b) Vowel count c) Display asterisk design d) Exit Select one of the above options: a n:7 Num 1: 12.5 Num 2: -77.2 Num 3: 30 Num 4: 382.9 Num 5: -27.44 Num 6: 80 Num 7: 4.5 Average:Max:Min:Middle:46.5302.977.2302.9 a) Statistics b) Vowel count c) Display asterisk design d) Exit Select one of the above options: b Enter a word: CDC CDC contains no vowels a) Statistics b) Vowel count c) Display asterisk design d) Exit Select one of the above options: b Enter a word: Encyclopedia Total Vowels: 6 A: A:E:12 I: 1 Y:1 a) Statistics b) Vowel count c) Display asterisk design d) Exit Select one of the above options: b Enter a word: Aluminum Total Vowels: 4 A:I:U:112 a) Statistics b) Vowel count c) Display asterisk design d) Exit Select one of the above options: c a) Statistics b) Vowel count c) Display asterisk design d) Exit Select one of the above options: d Terminated
Publicité