/* * Illustrates input data verification/validation (uses Type.java) * Suggested exercises: * - change the type of intervals (open/close) * - use if-else to read and validate a percentage value * (integer in the interval [0,100]) */ import java.util.Scanner; class CheckInput { public static void main (String[] args) { String input; int a; double x; Scanner scan = new Scanner(System.in); System.out.print("Enter an integer: "); a = scan.nextInt(); System.out.println(a + " belongs to [0,10): " + (a>=0 && a<10)); System.out.println(a + " does not belong to [0,10]: " + (a<0 || a>10)); System.out.println(); if (a>=0 && a<10) System.out.println(a + " is in the interval [0,10]"); else System.out.println(a + " is outside the interval [0,10]"); System.out.print("\nEnter an item: "); input = scan.next(); System.out.println("Integer: " + Type.isInteger(input)); System.out.println("Double: " + Type.isDouble(input)); System.out.println(); if (Type.isInteger(input)) System.out.println(input + " is of type Integer"); else if (Type.isDouble(input)) System.out.println(input + " is of type Double"); else System.out.println(input + " is of type String"); } }