Maximum and Minimum number of array elements


Write a program in java assign 10 different number in a single Dimensional Array and display the maximum and minimum number of array elements.

import java.io.*;

Public class Maxmin

{

public static void  main (String arg[])

{

InputStreamReader r1=new InputStreamReader (System.in);

BufferedReader in=new BufferedReader(r1);

int i,j,min,max;

int m[]=new int[10];

for(i=0;i<=10;i++)

{

System.out.println(“enter the number in the cell:”);

m[i]=Integer.parseInt(in.readLine());

}

max=m[0];

min=m[0];

for(i=0;i<=10;i++)

{

if(max<m[i])

max=m[i];

if(min>m[i])

min=m[i];

}

System.out.println(“The greatest number of the array elements=”+max);

System.out.println(“The smallest number of the array elements=”+min);

}}

Related Posts

Comments are closed.