In: Computer Science
Write a Java program that prompts a user for 10 integers. When completed it outputs the highest
number, the lowest number, the number of odd number, and the average of the numbers
The code is :
import java.io.*;
class Main {
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a[]=new int[10];
int i,j,c=0;
double s=0.0,avg=0.0;
System.out.println("Enter 10 numbers");
for(i=0;i<10;i++)
{
a[i]=Integer.parseInt(br.readLine()); // enter numbers
}
int max=a[0],min=a[0];
for(i=0;i<10;i++)
{
if(a[i]>max) // max check
{
max=a[i];
}
if(a[i]<min) //min check
{
min=a[i];
}
s=s+a[i];
avg=s/10; // average computation
if(a[i]%2!=0) // odd number checking
{
c++;
}
}
System.out.println("Highest number is "+max);
System.out.println("Lowest number is "+min);
System.out.println("Number of odd numbers are "+c);
System.out.println("Average is "+avg);
}
}
The screenshot of the code is :
The screenshot of the output is :