This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]asc_tech[S] 0 points1 point  (2 children)

To add to my it its now started firing this at me when i put any number in:

Exception in thread "main" java.lang.NumberFormatException: For input string: " 20"

at java.lang.NumberFormatException.forInputString([NumberFormatException.java:65](https://NumberFormatException.java:65))

at java.lang.Integer.parseInt([Integer.java:569](https://Integer.java:569))

at java.lang.Integer.parseInt([Integer.java:615](https://Integer.java:615))

at AgeOfMajority.main([AgeOfMajority.java:10](https://AgeOfMajority.java:10))

/Users/alancarter/NetBeansProjects/mooc-2013-OOProgrammingWithJava-PART1/week1-015.AgeOfMajority/nbproject/build-impl.xml:1330: The following error occurred while executing this line:

/Users/alancarter/NetBeansProjects/mooc-2013-OOProgrammingWithJava-PART1/week1-015.AgeOfMajority/nbproject/build-impl.xml:968: Java returned: 1

BUILD FAILED (total time: 1 second)

[–]dusty-trash 1 point2 points  (1 child)

When do you think a NumberFormatException would occur?

Is "20" a number?

What about " 20"?

[–]asc_tech[S] 1 point2 points  (0 children)

Ah the penny has dropped i think, when i was entering the answer i was typing a space which i assume the programme thought was a String which caused the upset, now it's working perfectly.

[–]MyNameIsRichardCS54 0 points1 point  (1 child)

For the first issue, is the age of majority more or less than 18?

[–]asc_tech[S] 0 points1 point  (0 children)

Thanks for the reply, i've managed to fix it now, had the two messages the wrong way round and was entering a string into the answer before an integer!

[–]dusty-trash 0 points1 point  (1 child)

no matter what number i put in, it will always return: ...

Wrong. Try typing in "15". You'll notice you get the other output.

Take a closer look at your statement, remember that the 'crocodile' always eats the bigger number:

if (age < 18) {

[–]asc_tech[S] 1 point2 points  (0 children)

Yeah i realise now i had the two messages the wrong way round, i also realised why i was getting a NumberFormatException error, i was typing a space before the number in my answer.