Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class vowels {
- public static void main(String[] args) {
- String input;
- int characters;
- int a = 0;
- int e = 0;
- int i = 0;
- int o = 0;
- int u = 0;
- JOptionPane.showMessageDialog(null,"This Program asks the user for a sentence, searches for all vowels, and displays the number of times each vowel appears in the sentence.","VOWELS PROJECT", JOptionPane.INFORMATION_MESSAGE);
- input = JOptionPane.showInputDialog("\n\nEnter the sentence to search:\n");
- characters = input.length();
- String input2 = input.toLowerCase();
- for(i = 0;i < input2.length(); i++) {
- char test = input2.charAt(i);
- if(test == 'a') {
- a++;
- }
- else if(test == 'e') {
- e++;
- }
- else if(test == 'i') {
- i++;
- }
- else if(test == 'o') {
- o++;
- }
- else if(test == 'u') {
- u++;
- }
- }
- JOptionPane.showMessageDialog(null,input +" has " + characters + " characters\n" + "There are " +a+" a's, "+e+" e's, "+i+" i's, "+o+" o's, and "+u+" u's.","Output", JOptionPane.INFORMATION_MESSAGE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement