Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHarold Hicks
467 PointsSo I found something
I am using my Terminal to create the if age is under 13 system.exit(0) and as I ran it I found as it was loading If I typed 11 before it asked me what my age was I could type 11 once more and it would run without exiting even know im under the age. I would like to know why.
import java.io.Console;
public class Hello {
public static void main(String[] args) {
Console console = System.console();
String ageOfPerson = console.readLine("What is your age? ");
int age = Integer.parseInt(ageOfPerson);
if (age < 13)
{
console.printf("Sorry you must be at lease 13 to use this APP.");
System.exit(0);
}
/* Some terms:
noun - Person, place or thing
verb - An action
adjective - A description used to modify or describe a noun
Enter your amazing code here!
*/
String name = console.readLine("Enter your Name : ");
String ag = console.readLine("Enter Adjective : ");
console.printf ("%s is very %s", name , ag);
}
}
4 Answers
Miroslav Kovac
11,454 PointsHmm, work for me in my local environemt, I did not use Workspaces.....
Scanner in = new Scanner(System.in);
in.nextLine();
System.out.print("What is you age: ");
String ageOfPerson = in.nextLine();
Maybe try to clear Scanner before input with in.nextline()
Miroslav Kovac
11,454 PointsMaybe you can try to use Scanner for input.
Scanner in = new Scanner(System.in);
System.out.print("What is you age: ");
String ageOfPerson = in.nextLine();
Ronald Williams
Java Web Development Techdegree Graduate 25,021 PointsMaybe this is an issue with workspaces. I made a java file with your code in a plain text editor and ran it through my terminal. When you run it on the terminal, it loads so fast that you can not enter 11 before it prompts with the question.
Harold Hicks
467 PointsI dont know what clear Scanner means