包项目;
import java.util.*;
public class age {
public static void age()
{
Scanner console = new Scanner (System.in);
int age;
System.out.print("Enter age: ");
age = console.nextInt();
if (age>=18);
{
System.out.println("Legit to vote");
}else
System.out.println("Not Legit to vote");
}
}
答案 0 :(得分:1)
您需要更改:
if (age>=18);
到
if (age>=18)
如果您使用了IDE并正确格式化了代码,那么这很明显:
前
public static void age() {
Scanner console = new Scanner(System.in);
System.out.print("Enter age: ");
int age = console.nextInt();
if (age >= 18);
{
System.out.println("Legit to vote");
}else
System.out.println("Not Legit to vote");
}
后
public static void age() {
Scanner console = new Scanner(System.in);
System.out.print("Enter age: ");
int age = console.nextInt();
if (age >= 18) {
System.out.println("Legit to vote");
} else {
System.out.println("Not Legit to vote");
}
}