66.1k views
0 votes
Write a Java application that inputs a series of 10 integers and determines and prints the largest and smallest integer. Use a counter-controlled while iteration.

User Vacri
by
5.8k points

1 Answer

6 votes

Answer:

import java.util.Scanner;

public class LargestSmallest {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.print("Enter 10 integers: ");

int num = in.nextInt();

int i = 1;

int min = num, max = num;

while (i < 10) {

num = in.nextInt();

if (num > max) max = num;

if (num < min) min = num;

i++;

}

System.out.println("Largest number: " + max);

System.out.println("Smallest number: " + min);

}

}

Step-by-step explanation:

A Java application that inputs a series of 10 integers and determines and prints the largest and smallest integer is written above.

User Joe Okatch
by
5.6k points