Untitled

 avatar
unknown
plain_text
a year ago
874 B
10
Indexable
// Importing required classes
import java.util.Scanner;
import java.util.Arrays;

// Drivers code
public class lab1{
	public static void main(String[] args){
	
	// Taking the size of array from the user
	Scanner scanner = new Scanner(System.in);
	System.out.print("Enter the size of the array : ");
	int size_of_array = scanner.nextInt();

	// initializing the array
	int array[]= new int[size_of_array];
	
	// taking the array elements from the user
	for(int i=0; i<array.length;i++){
		System.out.print("Enter the number at index "+i+" : ");
		array[i] = scanner.nextInt();
		}
	
	// closing the object as no longer in use
	scanner.close();
	
	// sorting the array
	Arrays.sort(array);

	// printing the sorted array
	System.out.println("Sorted array is : ");
	for(int i=0; i<array.length;i++){
		System.out.print(array[i]+" ");
		}
	}	
}
Editor is loading...
Leave a Comment