Initialize an array of size 10 and find the largest integer and smallest integer in the array. Also to display the array elements 5 per line then display in the new line the largest and smallest integer.
class array8
{
public static void main(String as[])
{
int arr[]={10,5,25,3,-4,100,1000,-10,77,38};
System.out.println("array numbers line no.1");
for(int i=0;i<=4;i++)
System.out.print(arr[i]+" ,");
System.out.println("\narray numbers line no.2");
for(int i=5;i<arr.length;i++)
System.out.print(arr[i]+" ,");
int max,min;
int i;
max=arr[0];
for(i=0;i<arr.length;i++)
{
if(arr[i]>max)
max=arr[i];
}
min=arr[0];
for(i=0;i<arr.length;i++)
{
if(arr[i]<min)
min=arr[i];
}
System.out.println("\nlargest no:"+max);
System.out.println("smallest no:"+min);
}
}
output:
D:\JavaPrograms\ArrayPrograms>javac array8.java
D:\JavaPrograms\ArrayPrograms>java array8
array numbers line no.1
10 ,5 ,25 ,3 ,-4 ,
array numbers line no.2
100 ,1000 ,-10 ,77 ,38 ,
largest no:1000
smallest no:-10
0 Comments
Post a Comment