Write a program in Java to input in numbers and find out the smallest and the largest number also display the average number
import java.io.*;
import java.lang.*;
import java.util.Scanner;
public class Main
{
static int[]args;
public static void main (String[]arg)
{
Main ob=new Main();
args=new int[10];
int avg=0;
Scanner sc =new Scanner(System.in);
for (int i = 0; i < 10; i++)
{ args[i]= sc.nextInt();
avg+=args[i];
}
ob.calculate();
System.out.println("Average ="+ avg/10);
}
void calculate()
{
int tmp=0,i;
for ( i = 0; i < 10; i++)
{
for(int j=0;j<args.length-1;j++)
{
if(args[j]>args[j+1])
{
tmp=args[j];
args[j]=args[j+1];
args[j+1]=tmp;
}
}
}
System.out.println("Max="+args[args.length-1]);
System.out.println("Min="+args[0]);
}
}
import java.lang.*;
import java.util.Scanner;
public class Main
{
static int[]args;
public static void main (String[]arg)
{
Main ob=new Main();
args=new int[10];
int avg=0;
Scanner sc =new Scanner(System.in);
for (int i = 0; i < 10; i++)
{ args[i]= sc.nextInt();
avg+=args[i];
}
ob.calculate();
System.out.println("Average ="+ avg/10);
}
void calculate()
{
int tmp=0,i;
for ( i = 0; i < 10; i++)
{
for(int j=0;j<args.length-1;j++)
{
if(args[j]>args[j+1])
{
tmp=args[j];
args[j]=args[j+1];
args[j+1]=tmp;
}
}
}
System.out.println("Max="+args[args.length-1]);
System.out.println("Min="+args[0]);
}
}
Comments