user5422552
user5422552

Reputation:

The else is having an error in this program

package project;

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

Upvotes: 0

Views: 24

Answers (1)

OldCurmudgeon
OldCurmudgeon

Reputation: 65793

You need to change:

if (age>=18);

to

if (age>=18)

If you had use an IDE and formatted your code properly this would have been obvious:

before

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

    }

after

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

    }

Upvotes: 1

Related Questions