-
String Variables In while loops
Hello all, i am having trouble making a while loop that has the user press Y or N , either Y to re-run the program, or N to quit ,,, for some reason it will only end the program when Y or N is entered.. here is the source...
/*
import java.io.*;
public class Assignment4
{
public static void main(String args[]) throws IOException
{
BufferedReader input= new BufferedReader(new InputStreamReader(System.in));
String choice="y";
while(choice=="y")
{
System.out.print("How many numbers do you have? > ");
int n = Integer.parseInt(input.readLine());
int x=0;
int largest=0;
int second=0;
int third=0;
while(x<n)
{
System.out.print("Input number "+ (x+1) + "> ");
int i = Integer.parseInt(input.readLine());
if(i>largest)
{
third = second;
second = largest;
largest = i;
}
else if(i > second)
{
third = second;
second = i;
}
else
{
third = i;
}
x+=1;
}
System.out.println("The three largest numbers are: " + largest + ", " + second + ", " + third);
System.out.println();
System.out.println("Compute again? <y/n>");
choice=input.readLine();
}
System.out.println("Normal termination!");
}
}
*/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks