-
-
Save andymuncey/f4137bb2ea7b41a1bd0092f3512f0570 to your computer and use it in GitHub Desktop.
Java code that requires refactoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.ac.chester; | |
public class Main { | |
public static void main(String[] args) { | |
System.out.println("Please type a phrase"); | |
java.util.Scanner scanner = new java.util.Scanner(System.in); | |
String text = scanner.nextLine(); | |
text = text.toLowerCase(); | |
int countA = 0; | |
int countE = 0; | |
int countI = 0; | |
int countO = 0; | |
int countU = 0; | |
for (int i = 0; i<text.length(); i++){ | |
char letter = text.charAt(i); | |
switch (letter){ | |
case 'a': | |
countA++; | |
break; | |
case 'e': | |
countE++; | |
break; | |
case 'i': | |
countI++; | |
break; | |
case 'o': | |
countO++; | |
break; | |
case 'u': | |
countI++; | |
break; | |
default: | |
break; | |
} | |
} | |
char mostCommonVowel = 'a'; | |
int highCount = countA; | |
if (countE > countA){ | |
mostCommonVowel = 'e'; | |
highCount = countE; | |
} | |
if (countI > highCount){ | |
mostCommonVowel = 'i'; | |
highCount = countI; | |
} | |
if (countO > highCount){ | |
mostCommonVowel = 'o'; | |
highCount = countO; | |
} | |
if (countU > highCount){ | |
mostCommonVowel = 'u'; | |
highCount = countU; | |
} | |
System.out.println("The most common vowel is: " + mostCommonVowel); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment