import java.io.* public class Arithmetic { public static void main(String[] args) { int x, y; System.out.print("Enter integer value for x: "); x = MyInput.readInt(); System.out.print("Enter integer value for y: "); y = MyInput.readInt(); // display arithmetic results System.out.println(); System.out.println(x + " + " + y + " = " + (x + y)); System.out.println(x + " - " + y + " = " + (x - y)); System.out.println(x + " * " + y + " = " + (x * y)); System.out.println(x + " / " + y + " = " + (x / y)); System.out.println(x + " % " + y + " = " + (x % y)); System.out.println(); // now try it for doubles double a, b; System.out.print("Enter double (float) value for a: "); a = MyInput.readDouble(); System.out.print("Enter double (float) value for b: "); b = MyInput.readDouble(); // display arithmetic results System.out.println(); System.out.println(a + " + " + b + " = " + (a + b)); System.out.println(a + " - " + b + " = " + (a - b)); System.out.println(a + " * " + b + " = " + (a * b)); System.out.println(a + " / " + b + " = " + (a / b)); System.out.println(a + " % " + b + " = " + (a % b)); System.out.println(); } } //------------------ // a class for reading various types from the keyboard (System.in) class MyInput { public static String readString() { String string = ""; BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); try { string = bufferedReader.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } return string; } public static int readInt() { return Integer.parseInt(readString()); } public static double readDouble() { return Double.parseDouble(readString()); } // test all the methods of this class public static void main(String[] args) { System.out.println("Testing 'readString()'"); System.out.print("Input your string : "); System.out.println("Your string was '" + readString() + "'"); System.out.println("\nTesting 'readInt()'"); System.out.print("Input your int : "); System.out.println("Your int was '" + readInt() + "'"); System.out.println("\nTesting 'readDouble()'"); System.out.print("Input your double : "); System.out.println("Your double was '" + readDouble() + "'"); } }