![]() |
The Future Is Behind You |
Home | About | Stories | Blog | Poetry | Programming |
ElseBelow is an example of an if/else statement. It checks against the input given by the user and outputs to the screen based off that input. If the input doens't match a choice, the program warns the user. import java.util.Scanner; public class Else { public static void main(String[] args) { System.out.println("Make a choice: "); System.out.println("1. Say Hello"); Scanner scan = new Scanner(System.in); System.out.print("Your choice: "); int choice = scan.nextInt(); if (choice == 1) { System.out.println("Hello World"); } else { System.out.println("That isn't a valid option"); } } } |
Copyright © 2003 - 2021 Kyle Eggleston |
a = b = c |