View Single Post
Old 03-20-2012, 06:02 AM   PM User | #1
sabi
New Coder

 
Join Date: Oct 2011
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
sabi is an unknown quantity at this point
Why does this while loop iterate

If the char variable again is initialized to 'N' then why does this loop iterate the first time

import java.util.Scanner;


public class teest
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);

int num;
String input;
char again = 'N';

while(again == 'Y' || again == 'y')
{
System.out.println("enter num: ");
num = keyboard.nextInt();
System.out.println("The number entered was " + num);
System.out.println("Do it agian?");
keyboard.nextLine();
input = keyboard.nextLine();
again = input.charAt(0);
}
}
}

Last edited by sabi; 03-20-2012 at 06:06 AM..
sabi is offline   Reply With Quote