Machine Problem
Write a program to ask the users to give a string or a sentence then the program will count the number of vowels, and consonants and display the results on the screen.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.Please subscribe to my channel https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg
Thank you very much for your support.
Program ListingProblem No. 7Write a program to ask the users to give a string or a sentencethen the program will count the number of vowels, and consonantsand display the results on the screen.Solution/* vowels_consonants.scalaProf. Jake Rodriguez Pomperada, MAED-IT, MITwww.jakerpomperada.blogspot.com and www.jakerpomperada.comjakerpomperada@gmail.comMarch 9, 2022 3:12 PM WednesdayBacolod City, Negros Occidental*/import java.util.Scanner;object vowels_consonants {def main(args: Array[String]) : Unit = {var input = new Scanner(System.in);var vowels = 0; var consonants = 0;var a = 0;print("\n");print("\tCount Vowels and Consonants Using Scala");print("\n\n");print("\tGive a String or a Sentence : ");var line = input.nextLine();line = line.toLowerCase();while (a < line.length){var ch = line.charAt(a);// check if character is any of a, e, i, o, uif (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {vowels=vowels+1;}// check if character is in between a to zelse if ((ch >= 'a' && ch <= 'z')) {consonants=consonants+1;}a=a+1;}print("\n")print("\t===== DISPLAY RESULTS ====\n\n");printf("\tNumber of Vowels : %d \n" ,vowels);printf("\tNumber of Consonants : %d " ,consonants);print("\n\n");print("\tEND OF PROGRAM");print("\n\n");}}
No comments:
Post a Comment