import java.util.Scanner; /** * Conditionals.java * Jeff Ondich, Carleton College, 2014-01-01 * Modified: Anna Rafferty, Carleton College, 2016-08-24 * Modified: Jed Yang, Carleton College, 2017-03-22 * * A tiny illustration of if-statements and console input. * * This is the Java half of a pair of parallel examples in Python and Java. * See conditionals.py. */ public class Conditionals { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Integer, please: "); int number = scanner.nextInt(); if (number > 100) { System.out.format("Gosh, %d is a big number\n", number); } else if (number == 23) { System.out.format("23 is my favourite number\n"); } else if (number >= 0) { System.out.format("%d is pretty small\n", number); } else { System.out.format("%d is negative\n", number); } } }