Java Saved Program: placid-home

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


//This Java program will take a string input, sort it and print
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Script" only */
public class Script
{
    static int arr[]=new int[10];
    static int n;
        static int temp;
    public static void main(String[] args)
    {
         
        System.out.println("Enter the number of elements in a array");
        Scanner s=new Scanner(System.in);
         n=s.nextInt();
        
    System.out.println("Enter the array");
        for(int i=0;i<n;i++)
        {
            System.out.println(i+"-->");
            arr[i]=s.nextInt();
        }
        
     //   MyClass hobj=new MyClass();
      //  hobj.selection();
      
      
       for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(arr[i]>arr[j])
                {
                    temp=arr[i];
                    arr[i]=arr[j];
                    arr[j]=temp;
                }
            }
        }
        
          for(int i=0;i<n;i++)
        {
            System.out.println(arr[i]+"\n");
        }
         s.close();
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs