Advertisement
Waliullah8328

Asending array

Jan 25th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.  
  2. package basicdata1;
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class AsendeningOrder {
  8.     public static void main(String[] args) {
  9.         Scanner input = new Scanner(System.in);
  10.         int[] num = new int[30];
  11.         int n,temp;
  12.         System.out.print("Enter how many you want to insert: ");
  13.         n = input.nextInt();
  14.         System.out.println("Please enter "+n+" your number : ");
  15.         for (int i = 0; i < n; i++) {
  16.             num[i] = input.nextInt();
  17.            
  18.         }
  19.         for (int j = 0; j < n; j++) {
  20.             for (int k = j+1; k < n; k++)
  21.             {
  22.               if(num[j]> num[k])
  23.               {
  24.                  temp = num[j];
  25.                  num[j] = num[k];
  26.                  num[k] = temp;
  27.               }
  28.             }
  29.            
  30.         }
  31.         System.out.println("The numbers arranged in ascending order are given below");
  32.         for (int j = 0; j < n; j++) {
  33.             System.out.println(num[j]);
  34.         }
  35.        
  36.     }
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement