![]() |
The Future Is Behind You |
Home | About | Stories | Blog | Poetry | Programming |
Else IfElse If applys a second condition to the test if the first if statement returns false. import java.util.Scanner; public class ElseIf { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("What's your age? "); int age = scan.nextInt(); if (age > 20) { System.out.println("You can do it all, you're old enough."); } else if (age > 17) { System.out.println("You can drive"); System.out.println("You can vote"); System.out.println("You can't drink"); } else if (age > 16) { System.out.println("You can drive"); System.out.println("You can't vote"); } else if (age < 16) { System.out.println("You can't drive."); System.out.println("You can't vote."); } } } Add some more else if statements to test for more conditionals. |
Copyright © 2003 - 2021 Kyle Eggleston |
a = b = c |