Relco
10-23-2006, 08:48 PM
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');
}
}
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');
}
}