Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

if/else variable not working. \"else\" is getting a red underline nomatter what

ID: 3812004 • Letter: I

Question

if/else variable not working. "else" is getting a red underline nomatter what I do. Syntax error on token "else", delete token.

import java.util.Scanner; public class Progrom210 {static Scanner fighter - new Scanner(System.in); public static void main(String[] args) {int age; System.out.print("Please enter your age: "); age - fighter.nextlnt(); if (age >= 21); {System.out.print("Your age is " + age); System.out.println(", you are old enough to buy alcohol");} else {System.out.println("You are not old enough to buy alcohol because you are " + age);}}}

Explanation / Answer

Hi

Please find the below working code

Program210.java

import java.util.Scanner;


public class Program210 {

   static Scanner figher = new Scanner(System.in);
  
   public static void main(String[] args) {
       int age;
       System.out.print("Pleae enter your age: ");
       age = figher.nextInt();
       if(age >= 21){
           System.out.print("Your age is "+age);
           System.out.println(", you are old enough to buy alcohol");
       }
       else {
           System.out.println("You are not old enough to but alcohol because you are "+age);
       }
   }

}

Output:

Pleae enter your age: 33
Your age is 33, you are old enough to buy alcohol

Pleae enter your age: 11
You are not old enough to but alcohol because you are 11