Java Code :
import java.util.Scanner;
public class Vowel{
public static void main(String[] args) {
//variable to store the sentence from user
String sentence;
//variables to stores vowels and non-vowels
int vowels = 0,consonants = 0;
//Scanner to take input from user
Scanner sc = new Scanner(System.in);
//taking the sentence from user
System.out.print("Enter zzz to exit or
sentence");
sentence = sc.nextLine();
//if sentence not equals to "zzz" then we continue
until they enter
while(!sentence.equals("zzz")){
//iterating character by character
in sentence
for(int
i=0;i<sentence.length();i++){
//checking for
vowels if character is vowel increse vowels other wise
consonants
if((sentence.charAt(i) == 'a' || sentence.charAt(i) == 'A')
||
(sentence.charAt(i) == 'e' || sentence.charAt(i)
== 'E') ||
(sentence.charAt(i) == 'i' || sentence.charAt(i)
== 'I') ||
(sentence.charAt(i) == 'o' || sentence.charAt(i)
== 'O') ||
(sentence.charAt(i) == 'u' || sentence.charAt(i)
== 'U')
){
vowels++;
}else{
if(sentence.charAt(i) != ' ' &&
sentence.charAt(i) != '\n'){
consonants++;
}
}
}
//again asking to user enter
sentence
System.out.print("Enter a sentence
or ZZZ to exit ");
sentence = sc.nextLine();
}
//printing the vowels and non-vowels
System.out.println("Total number of vowels "+vowels);
System.out.println("Total number of non-vowels "+consonants);
//printing the percentage by calculating
(no.vowels*100)/totalcharacters
System.out.println("Percent
"+(double)vowels*100/(consonants+vowels) + "%");
sc.close();
}
}
Output :
Please up vote.If any doubt comment below.I will answer.Please up vote.Thank You.
Ms. Marple is an English teacher at CCCC. She has a theory that more than 20%...
In Java please Only use methods in the purpose. Thank you The purpose of this assignment is to help you learn Java identifiers, assignments, input/output nested if and if/else statements, switch statements and non-nested loops. Purpose Question 2-String variables/Selection & loops. (8.5 points) Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline), converts the string into Ubbi...
Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...
Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...