In: Computer Science
Write a Java program to do the following USING ARRAYS
1) input 15 integers (input validation, all numbers must be between 0 and 100)
2) find the largest number.
3) Find the Smallest Number
4) Find the Sum of all numbers in the Array
Display:
Largest Number
Smallest Number
Sum of all numbers
the original Array
DO NOT USE METHODS OR FUNCTIONS
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner s = new
Scanner(System.in);
int a[] = new int[15];
int flag = 0, sum = 0, max = -1,
min = 101;
while(true)
{
sum = 0;
max = -1;
min = 101;
System.out.print("Enter the 15
elements : ");
for(int i = 0; i < 15;
i++)
{
int n = s.nextInt(); // read the
elemetns
if(n > 0 && n <
100)
{
a[i] = n;
sum = sum + n; // summation of
numbers
if(n < min)
{
min = n; // find minimum
}
if(n > max)
{
max = n; // find maximum
}
}
else{
System.out.println("Number should
be between 0 and 100");
flag = 1;
}
}
if(flag == 1)
{
flag = 0;
continue;
}
else{
break;
}
}
System.out.println("Enter the largest number : " +
max); // print the largest number
System.out.println("Enter the smallest number : " +
min); // print the smallest number
System.out.println("Sum of all numbers : " + sum); //
print the summation of number
System.out.print("Print the original array : "); //
print the original array
for(int i = 0; i < 15; i++)
{
System.out.print(a[i] + " ");
}
}
}
OUTPUT :