If statements Evaluations
Posted
by
user2464795
on Stack Overflow
See other posts from Stack Overflow
or by user2464795
Published on 2013-11-08T15:47:13Z
Indexed on
2013/11/08
15:53 UTC
Read the original article
Hit count: 111
java
Using the code below I get this result even though I put in a number that is greater than 18.
run:
How old are you? 21
You have not reached the age of Majority yet!
BUILD SUCCESSFUL (total time: 3 seconds)
I am new to java and trying to self learn can anybody help?
import java.util.Scanner;
public class Chapter8 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
// TODO code application logic here
//Excercise 15
System.out.print("How old are you? ");
int x = Integer.parseInt(reader.nextLine());
if (x > 18){
System.out.println("You have not reached the age of Majority yet!");
}else {
System.out.println("You have reached the age of Majority!");
}
© Stack Overflow or respective owner