其他人在这个程序中有错误

时间:2015-10-08 10:12:32

标签: java if-statement

包项目;

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");
    }
}

1 个答案:

答案 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");
        }

    }