Tested Java Programs

Just another WordPress.com weblog

Program to find sum,average,minimum and maximum of N numbers using input from keyboard

/* Program to find sum,average,minimum and maximum of N numbers using input from keyboard */

import java.io.*;
class prog_1b
{
public static void main(String args[])throws IOException
{
int k,sum=0,i,count=0,max,min,n;
int arr[] = new int[10];
float avg;
System.out.println(“Enter how many numbers you want to enter : “);
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str;
str=br.readLine();
k = Integer.parseInt(str);

for(i=0;i<k;i++)
{
System.out.println(“Enter the number : “);
BufferedReader br1= new BufferedReader(new InputStreamReader(System.in));
str=br1.readLine();
arr[i] = Integer.parseInt(str);
}
max = arr[0];
min = arr[0];
while(count < k)
{
sum += arr[count];
if(min > arr[count])
min = arr[count];
if (max < arr[count])
max = arr[count];
count += 1;
}
avg = sum/k;
System.out.println(“The sum is ” +sum);
System.out.println(“The average is ” +avg);
System.out.println(“Maximum is ” +max);
System.out.println(“Minimum is ” +min);

}
}

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: