88.0k views
2 votes
Write a simple java program with the following requirements:

A. Create an array to store ten integers
B. Prompt the user to enter the array elements and store them in the array
C. Display the following
i. Elements/integers stored in the array
ii. Odd integers present in the array
iii. Integers that are multiples of five
iv. Sum of all the integers present in the array
v. Highest/maximum integer in the array vi. Lowest integer in the array

User Tarun Gaba
by
6.9k points

1 Answer

4 votes

Final answer:

A Java program is provided that prompts the user to enter ten integers, stores them in an array, and then displays various details about those integers including the complete list, the odd integers, those that are multiples of five, the sum, and the highest and lowest integers.

Step-by-step explanation:

In this task, we will create a simple Java program to meet the following requirements:

Create an array to store ten integers.

Prompt the user to enter the array elements and store them in the array.

Display the following:

Elements/integers stored in the array.

Odd integers are present in the array.

Integers that are multiples of five.

The sum of all the integers present in the array.

Highest/maximum integer in the array.

Lowest integer in the array.

Here is a sample Java program that achieves the goals above:

import java.util.Scanner;

public class ArrayProcessor {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] integers = new int[10];
int sum = 0;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;

// Prompt the user to enter integers
for (int i = 0; i < integers.length; i++) {
System.out.print("Enter integer " + (i + 1) + ": ");
integers[i] = scanner.nextInt();
sum += integers[i];
if (integers[i] > max) max = integers[i];
if (integers[i] < min) min = integers[i];
}

System.out.println("\\Elements in the array:");
for (int num : integers) {
System.out.println(num);
}

System.out.println("\\Odd integers:");
for (int num : integers) {
if (num % 2 != 0) {
System.out.println(num);
}
}

System.out.println("\\Multiples of five:");
for (int num : integers) {
if (num % 5 == 0) {
System.out.println(num);
}
}

System.out.println("\\Sum of all integers: " + sum);
System.out.println("\\Highest integer: " + max);
System.out.println("\\Lowest integer: " + min);

scanner.close();
}
}

To use this program, compile it with a Java compiler and run it. The program will prompt you to enter integers one by one and then display the required information. Note that elements will be accepted in the order they are entered, and the program includes logic to determine and display odd integers, multiples of five, sum, max, and min of the integers entered.

User Chrisortman
by
8.1k points