Write a java program to accept 5 numbers using command line arguments sort and display them.
import java.io.*; public class sort { public static void main(String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int [] arr=new int[5]; for(int i=0;i<5;i++) //Array Initialization { arr[i]=Integer.parseInt(br.readLine()); } int temp = 0; //Temporary variable to store the element for (int i = 0; i < 5; i++) //Holds each Array element { for (int j = i+1; j < 5; j++) //compares with remaining Array elements { if(arr[i] > arr[j]) //Compare and swap { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } System.out.println(); //Displaying elements of array after sorting System.out.println("Elements of array sorted in ascending order: "); for (int i = 0; i < 5; i++) { System.out.print(arr[i] + " "); } } }
java sort 4 6 1 7 8 Elements of array sorted in ascending order: 1 4 6 7 8
6 Comments
stelanfizu1998 Erin Allen https://marketplace.visualstudio.com/items?itemName=persmolper-mi.Army-Of-Numbers-gratuita
ReplyDeleteilblinticwcir
Mrecucae_pu Monica Fowler Download
ReplyDeleterimilemo
traninqui-no_Paterson Mela Jordan click here
ReplyDeletemontranhedsschul
saucomZplet-po-Tulsa Cindy Lucas link
ReplyDeleteclick
click here
download
caltighnaten
stinanZbron_se George Strickler Adobe After Effects
ReplyDeletePositive Grid BIAS FX 2 Elite 2.4.5.6360
Rufus
IObit Driver Booster Pro 9.5.0.237
ulpleasransre
Gcc string.c
ReplyDeleteThanks,To visit this blog.