Hey guys,
I recently wrote this program and it compiles and works but I have two issues that need addressing and I'm a bit confused on how to solve them.
Question 1)
System.out.println("What's your name?");
name = Scan.nextLine();
System.out.println("How old are you?");
age = Scan.nextInt();
I always thought Scan.next and so had to start with a lowercase s. It does not work with a lower case s (works with a capital S though), I get this error when I do use it:
Error:
AgeStatus.java:18: cannot find symbol
symbol : variable scan
location: class AgeStatus
name = scan.nextLine();
^
1 error
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
(the program still runs but I'd like to learn why I still got a compile error and I'm a newb programmer so any help is appreciated :P)
and my second question is: How can I put everything on one line? when I run the program it outputs as this:
----jGRASP exec: java AgeStatus
What's your name?
Dude
How old are you?
26
Dude is 26 years old and is
young.
----jGRASP: operation complete.
I'd like my program to read out as:
Dude is 26 years old and is young.
Here is my program:
// AgeStatus.java
import java.util.Scanner;
public class AgeStatus
{
// Prompts for name and age
public static void main(String[] args)
{
Scanner Scan = new Scanner (System.in);
String name;
int age;
System.out.println("What's your name?");
name = Scan.nextLine();
System.out.println("How old are you?");
age = Scan.nextInt();
System.out.println(name+" is "+age+" years old and is");
if(age < 30)
{
System.out.println("young.");
}
else if( age >= 30 && age < 60)
{
System.out.println("middle-aged.");
}
else if( age > 60)
{
System.out.println("old!");
}
}
}
Thanks in advance!