The program below is the solution to Deitel’s Java How to Program (9th Edition) Chapter 2 Exercise 2.24.
Question: Write an application that reads five integers and determines and prints the largest and smallest integers in the group. Use only the programming techniques you learned in this chapter.
Largest And Smallest Integers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
*
* Exercise 2.24 - Largest And Smallest Integers
* This Program Determines The Largest And Smallest of Any Five Integer Numbers
*
*/
import java.util.Scanner;
publicclassEx02_24{
publicstaticvoidmain(String[]args){
Scanner value=newScanner(System.in);
intnum1;
intnum2;
intnum3;
intnum4;
intnum5;
intlargest;
intsmallest;
System.out.print("\nEnter Your First Number: ");
num1=value.nextInt();
System.out.print("\nEnter Your Second Number: ");
num2=value.nextInt();
System.out.print("\nEnter Your Third Number: ");
num3=value.nextInt();
System.out.print("\nEnter Your Fourth Number: ");
num4=value.nextInt();
System.out.print("\nEnter Your Fifth Number: ");
num5=value.nextInt();
largest=num1;// assume largest is the first number
if(num2>largest)
largest=num2;
if(num3>largest)
largest=num3;
if(num4>largest)
largest=num4;
if(num5>largest)
largest=num5;
smallest=num1;// assume smallest is the first number