I have checked and checked and I cant see why when I type in a word with two consonants it gives me TWO outputs. Here is my code:
import java.util.Scanner;
public class piglatinJethroB {
public static void main(String[]args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to the Pig Latin Translator!");
System.out.println("Type in a word and I will translate it into pig latin");
String word = input.next();
String tolowercase = word.toLowerCase();
char s = tolowercase.charAt(0);
char n = tolowercase.charAt(1);
String sub1 = tolowercase.substring(1);
String sub2 = tolowercase.substring(2);
String newword;
char a = 'a';
char e = 'e';
char i = 'i';
char o = 'o';
char u = 'u';
if (s == a || s == e || s == i || s == o || s == u ) {
newword = tolowercase + "hay";
System.out.println(newword);
return;
} else if (s != a && s != e && s != i && s != o && s != u) {
newword = sub1 + s + "ay";
System.out.println(newword);
if (n != a && n != e && n != i && n != o && n != u) {
newword = sub2 + s + n + "ay";
System.out.println(newword);
}
}
}
}
What can I do to fix this?
Aucun commentaire:
Enregistrer un commentaire