Accepting input from Command-Line in Java and taking 10 numbers. Print the smallest and largest by sorting the list using Bubble Sort.
Language : Java
[sourcecode language='c']
//Using Command Line take an Array of 10 nos and print the Smallest and Largest
class ArrNo
{
public static void main(String args[]){
int arr[]=new int[10];
int i,j,temp;
for(i=0;i<10;i++)
arr[i] = Integer.parseInt(args[i]);
for(i=0;i<10;i++)
{ for(j=0;j<9;j++)
{
if(arr[j]>arr[j+1])
{ temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
System.out.println(“Sorted List :”);
for(i=0;i<10;i++)
System.out.println(arr[i]);
System.out.println(“The Smallest Number is : “+ arr[0]);
System.out.println(“The Largest Number is : ” + arr[9]);
}
}
[/sourcecode]







{ 3 comments… read them below or add one }
Nyc work dude..
Nyc work dude..
nice work .. i just shared with java devs… looking for more such codes..