CODE
// tells the user what to enter if y
if (input.equals ("y") )
System.out.println("\nPlease insert a letter EX: A or a, and press return\n");
input2 = kboard.nextLine();
input2 = input2.toLowerCase();
the above section is the problem with this code.
When you check for "y" you only apply the if statement to the next line - System.out....
if input is not "y" you only bypass that line and still try to read in for input2.
Add a curly brace after the if (input.equals ("y") )-
CODE
if (input.equals ("y") )
{
System.out.println("\nPlease insert a letter EX: A or a, and press return\n");
input2 = kboard.nextLine();
input2 = input2.toLowerCase();
then add the closing brace after
CODE
|| testInput.equals("x") || testInput.equals("y")
|| testInput.equals("z"))
System.out.println("\nYou have entered a consonant\n\n");
}
else
{
//if something else is inputed
System.out.println("\nPlease follow directions\n\n");
}
this way you check for "y",
if not you only print the warning message.
QUOTE(stutfly @ 4 Sep, 2008 - 08:38 PM)

I am having trouble the code works and runs but if I dont enter y or n at the begining or end I have to push enter twice for it to read out the follow directions warning. I think that it is a problem with my loop I have tried alot of things but none have worked please help.
CODE
/**
* @(#)VowelConst.java
*
* VowelConst application
*
* @author
* @version 1.00 2008/8/27
*/
import java.util.Scanner;
public class VowelConst {
public static void main(String[] args) {
//declared strings
String input, input2, input3;
//used for keyboard input
Scanner kboard = new Scanner (System.in);
//Title
System.out.println("WELCOME TO THE VOWEL and CONSONANT GAME");
System.out.println("---------------------------------------");
// asks the user if they want to play the game
System.out.println("\nWould you like to play the game?\n If yes enter Y or y\n If No enter N or n and press return\n\n");
input = kboard.nextLine();
input = input.toLowerCase();
// Reapeats the program
while (!input.equals ("n") )
{
// tells the user what to enter if y
if (input.equals ("y") )
System.out.println("\nPlease insert a letter EX: A or a, and press return\n");
input2 = kboard.nextLine();
input2 = input2.toLowerCase();
// ends if n
if (input.equals ("n") )
System.out.print("\n");
// for vowel inputs
if (input2.equals ("a") ||input2.equals ("e") ||input2.equals ("i") ||input2.equals ("o") ||input2.equals ("u"))
System.out.println("\nYou have entered a vowl\n\n");
// for consonant inputs
else if (input2.equals ("b") || input2.equals ("c") || input2.equals ("d") || input2.equals ("f") || input2.equals ("g") || input2.equals ("h")
|| input2.equals ("j") || input2.equals ("k") || input2.equals ("l") || input2.equals ("m") || input2.equals ("n") || input2.equals ("p")
|| input2.equals ("q") || input2.equals ("r") || input2.equals ("s") || input2.equals ("t") || input2.equals ("v") || input2.equals ("w")
|| input2.equals ("x") || input2.equals ("y") || input2.equals ("z") )
System.out.println("\nYou have entered a consonant\n\n");
else
//if something else is inputed
System.out.println("\nPlease follow directions\n\n");
// Asks the user if they want to play again
System.out.println("\nWould you like to play the game?\n If yes enter Y or y\n If No enter N or n and press return\n\n");
input = kboard.nextLine();
input = input.toLowerCase();
}
}
}
Edited to add the [ code] tag. Please post your code like this:
