Description: Design and write a program that processes 25 integer values (intege
ID: 3875640 • Letter: D
Question
Description: Design and write a program that processes 25 integer values (integers) as follows. --> count all input values (ALL) --> count values, excluding immediate duplicates (NODUP) Note: 1 2 2 3 4 2; excluding duplcates: 1 2 3 4 2 --> Compute statistics on ALL and NODUP: ALL: sum, average (2 decimal places), min, max NODUP: sum, average (3 decimal places), max, min Required Input/Output Formats: Input Prompt: Enter 25 integer values: Output labels/format: ALL COUNT = xxx NODUP COUNT = xxx ALL STATS: SUM = x AVG = x.xx MIN = x MAX = x NODUP STATS: x:SUM x.xxx:AVG x:MAX x:MIN Example: 1 2 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 all count = 25 / nodup count = 5 ... NOTE: In the formatting a single 'x' means "no field width required', but '.xx' means 2 decimal places, '.xxx' means 3.
Explanation / Answer
import java.text.DecimalFormat;
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
int n=25,max=0,min=0,i,sum=0,c=0,max1=0,min1=0,sum1=0,avg1=0;
float avg=0.0f; //variable declaration
int a[]=new int[n];
DecimalFormat df = new DecimalFormat("#.##");
DecimalFormat df1 = new DecimalFormat("#.###");
Scanner sc=new Scanner(System.in);
System.out.println("Enter 25 integer values");
for(i=0;i<n;i++) //accepting the values from the user
{
a[i]=sc.nextInt();
}
min=a[0];
for(i=0;i<n;i++)
{
sum=sum+a[i]; //calculating sum
if(a[i]>max)
max=a[i]; //calculating max
if(a[i]<min)
min=a[i]; //calculating min
}
avg=sum/n; //calculating min
int j;
for(i=0;i<n;i++) //coiunting for distinc element
{
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
c=c+0;
else
c=c+1;
}
}
int k=(-1*(n-c));
//sorting the element
for(i=0;i<a.length;i++)
{
for(j=i;j<a.length;j++)
{
if(a[i]>a[j])
{
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
int dg=0; //having the distinct elementin thye array
a[dg]=a[0];
for(i=0;i<a.length;i++)
{
if (a[dg]!=a[i])
{
dg++;
a[dg]=a[i];
}
}
min1=a[0];
for(i=0;i<=dg;i++)
{
sum1=sum1+a[i]; //calculating sum
if(a[i]>max1)
max1=a[i]; //calculating max
if(a[i]<min1)
min1=a[i]; //calculating min
}
avg1=sum1/k;
System.out.println("ALL COUNT = "+n); //displaying the result
System.out.println("NODUP COUNT = "+k);
System.out.println();
System.out.println("ALL STATS: SUM = "+sum+" AVG = "+df.format(avg)+" MIN = "+min+" MAX = "+max);
System.out.println("NODUP STATS: SUM = "+sum1+" AVG = "+df1.format(avg1)+" MIN = "+min1+" MAX = "+max1);
}
}