/* FindRemainder CIS 160 David Klick 2004-08-28 This program finds the remainder of two numbers. It will ask for two integers and display the remainder obtained when dividing the largest by the smallest. The program will also display the floating-point value of the division and the integer value of the division. */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class FindRemainder { public static void main(String[] args) throws IOException { // set up keyboard object for input BufferedReader kbd = new BufferedReader( new InputStreamReader(System.in)); // declare variables to store user input int num1, num2; // declare variables to store remainder and divison results int remainder, intResult; double fpResult; // declare variable we will need for temp storage int temp; // get numbers from user System.out.print("Enter an integer: "); num1 = Integer.parseInt(kbd.readLine()); System.out.print("Enter another integer: "); num2 = Integer.parseInt(kbd.readLine()); // make sure num1 is larger than num2 if (num1 < num2) { temp = num1; num1 = num2; num2 = temp; } // get remainder and result of division remainder = num1 % num2; intResult = num1 / num2; fpResult = ((double) num1) / num2; // display all results System.out.println("\nThe numbers entered were " + num1 + " and " + num2 + "\nnum1 / num2 = " + intResult + " (integer result)" + "\nremainder = " + remainder + "\nnum1 / num2 = " + fpResult + " (fp result)" ); } } /* Sample from one run of program: Enter an integer: 5 Enter another integer: 92 The numbers entered were 92 and 5 num1 / num2 = 18 (integer result) remainder = 2 num1 / num2 = 18.4 (fp result) */