80.3k views
1 vote
Anyone can help me with this?

Write a program that places 10 random integers in the range of 1 - 20 into an array. Your program should then print the list of numbers, print the list of numbers in reverse order, find and print the largest number on the list, find and print the smallest number on the list, print the total of the numbers, and print the average of the numbers to the nearest hundredth. All output should be neatly formatted with headers for each part of the program (ex. "The list of numbers: ", "The numbers in reverse order is: ", "The Smallest Number on the list is: ", etc...

User Domenikk
by
4.9k points

1 Answer

5 votes

Answer:

/*

Find Largest and Smallest Number in an Array Example

This Java Example shows how to find largest and smallest number in an

array.

*/

public class FindLargestSmallestNumber {

public static void main(String[] args) {

//array of 10 numbers

int numbers[] = new int[]{32,43,53,54,32,65,63,98,43,23};

//assign first element of an array to largest and smallest

int smallest = numbers[0];

int largetst = numbers[0];

for(int i=1; i< numbers.length; i++)

{

if(numbers[i] > largetst)

largetst = numbers[i];

else if (numbers[i] < smallest)

smallest = numbers[i];

}

System.out.println("Largest Number is : " + largetst);

System.out.println("Smallest Number is : " + smallest);

}

}

/*

Output of this program would be

Largest Number is : 98

Smallest Number is : 23

*/

Step-by-step explanation:

User Ahwar
by
5.6k points