Computer Science, asked by ishaanmaharjan16, 7 months ago

write a program display the difference of the greatest and smallest numbers among any 8 numbers

can anyone help me in this

Answers

Answered by Vyomsingh
1

Answer:

class differ

{

void main(int a,int b,int c,int d,int e,int f,int g,int h)

{

double k=Math.max(a,Math.max(b,Math.max(c,Math.max(d,Math.max(e,Math.max(f,Math.max(g,h)))))));

double l=Math.min(a,Math.min(b,Math.min(c,Math.min(d,Math.min(e,Math.min(f,Math.min(g,h)))))));

double dif=k-l;

System.out.println("difference between max and min is:"+dif);

}

}

Answered by anindyaadhikari13
23

Check my answer.

Previous answer is too complicated.

import java.util.*;

class x

{

static void main()

{

Scanner sc = new Scanner(System.in);

System.out.println("Enter 8 numbers. ");

int a[] = new int[8];

for(int I=0;I<8;I++)

a[I]=sc.nextInt();

int max=a[0], min =a[0];

for(int I=0;I<8;I++)

{

if(a[I] > max)

max = a[I];

if(a[I]<min)

min=a[I];

}

int d=max-min;

System.out.print(" Difference is: "+d);

}

}

Similar questions