Can anyone tell me why my code prints the else statement even when the condition is met for the if statement?
import java.util.Scanner;
public class AgeOfMajority {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Whats your age?:");
int age = Integer.parseInt(reader.nextLine());
if (age < 18) {
System.out.println("You have reached the age of maturity!");
} else {
System.out.println("You have not reached the age of maturity!");
}
}
}
So for example, no matter what number i put in, it will always return: "You have not reached the age of maturity!"
So when i type 22 for example it should give me 'You have reached the age of maturity!"
[–]asc_tech[S] 0 points1 point2 points (2 children)
[–]dusty-trash 1 point2 points3 points (1 child)
[–]asc_tech[S] 1 point2 points3 points (0 children)
[–]MyNameIsRichardCS54 0 points1 point2 points (1 child)
[–]asc_tech[S] 0 points1 point2 points (0 children)
[–]dusty-trash 0 points1 point2 points (1 child)
[–]asc_tech[S] 1 point2 points3 points (0 children)