|
-
October 23rd, 2006, 08:07 PM
#1
Do..While - No termination.
This program asks the user to input
Name
Age
Height
(or press 'q' to quit)
If details are age = 30-40 or height 180-195
Message: +Name is suspect
my problem is that when i type q
the program doesnt terminate
so i guess the problem is at the 'while' statement
can anyone tell me whats wrong?
Thanks
import java.util.*;
public class CrimeInvestigation
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String name;
int age,height;
do
{
System.out.print("Name of suspect (press 'q' to quit): ");
name = sc.next();
System.out.print("Age: ");
age = sc.nextInt();
System.out.print("Height: ");
height = sc.nextInt();
if ((age >= 30 && age <= 40) || (height >= 180 && height <= 195))
{
System.out.print(name+" is a suspect");
}
else
{
System.out.print(name+" is not a suspect");
}
System.out.println("");
System.out.println("");
} while (name != 'q');
}
}
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
|
Click Here to Expand Forum to Full Width
|