|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help With if's
Hi i'm a year 1 student at university and this is one of my first assignments. just having a little trouble with it.
This is the code import java.util.Scanner; class TheatreBookingSystem { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int age; System.out.print("Welcome To the Theatre Booking System"); System.out.println("please Enter Customers Age:>"); age = scan.next(); if (age >= 18); { System.out.println("You can see the Film, Puppet Show, Sax Player and The Play"); } else if (age.equals ("< 18") && >= 15) { System.out.println("You Can See the puppet Show, Sax Player and The Show"); } else (age =>12) { System.out.println("You can see the Sax Player"); } if else { System.out.println("You can see the puppet show"); } } } this is the compile error H:\Desktop\AO BBIT\Programming 1\Assignment 2\TheatreBookingSystem.java:23: 'else' without 'if' else if (age.equals ("< 18") && >= 15) ^ 1 error Tool completed with exit code 1 |
|
#2
|
|||
|
|||
|
Very common mistake. It's not so bad. What's somewhat bad is the ones you will probably see after fixing that one:
Just remove the semicolon from if(age >= 18); So I suggest you change Code:
if(age >= 18);
age = scan.next();
else if (age.equals ("< 18") && >= 15)
else (age =>12)
to Code:
if(age >= 18) age = scan.nextInt(); //this will look for an int. else if (age <= 18 && age >= 15) else if (age =>12) Finally, there is a statement that migth give you another error: Code:
if else
{
System.out.println("You can see the puppet show");
}
Just remove the "if" in front of the "else" and that should do the trick. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Help With if's |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|