// Largest4.java Copyright (c) 2006 Kari Laitinen // http://www.naturalprogramming.com // 2006-02-12 File created. // 2006-02-12 Last modification. // This program is a solution to the first task of Exercise 6-1. // The solution to the second task is in file // LargestSmallest4.java. import java.util.* ; class Largest4 { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; System.out.print( "\n This program can find the largest of four" + "\n integers you enter from the keyboard. \n\n") ; System.out.print( " Please, enter the first integer: " ) ; int first_integer = keyboard.nextInt( ) ; System.out.print( " Please, enter the second integer: " ) ; int second_integer = keyboard.nextInt( ) ; System.out.print( " Please, enter the third integer: " ) ; int third_integer = keyboard.nextInt( ) ; System.out.print( " Please, enter the fourth integer: " ) ; int fourth_integer = keyboard.nextInt( ) ; int found_largest_integer ; if ( first_integer > second_integer ) { found_largest_integer = first_integer ; } else { found_largest_integer = second_integer ; } if ( third_integer > found_largest_integer ) { found_largest_integer = third_integer ; } if ( fourth_integer > found_largest_integer ) { found_largest_integer = fourth_integer ; } System.out.print( "\n The largest integer is " + found_largest_integer + ".\n" ) ; } }