import java.io.*;
class Sort
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
{
// create an int type array
System.out.println("how many element");
int n=Integer.parseInt(br.readLine());
int arr[]=new int [n];
//accept integer element into the array
for(int i=0; i<n;i++)
{
System.out.println("Enter int ");
arr[i]=Integer.parseInt(br.readLine());
}
// use bubble to sort technique to short the intergers
int limit =n-1;
boolean flag=false;
int temp;
for(int i=0; i<limit;i++)
{
for(int j=0;j<limit-i;j++)
{
if(arr[j]> arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
flag=true;
}
}
if (flag==false)break;
else flag=false;
}
// display the sorted arry
System.out.println("the sorted array is :");
for(int i=0; i<n;i++)
System.out.println(arr[i]);
}
}
}
class Sort
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
{
// create an int type array
System.out.println("how many element");
int n=Integer.parseInt(br.readLine());
int arr[]=new int [n];
//accept integer element into the array
for(int i=0; i<n;i++)
{
System.out.println("Enter int ");
arr[i]=Integer.parseInt(br.readLine());
}
// use bubble to sort technique to short the intergers
int limit =n-1;
boolean flag=false;
int temp;
for(int i=0; i<limit;i++)
{
for(int j=0;j<limit-i;j++)
{
if(arr[j]> arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
flag=true;
}
}
if (flag==false)break;
else flag=false;
}
// display the sorted arry
System.out.println("the sorted array is :");
for(int i=0; i<n;i++)
System.out.println(arr[i]);
}
}
}
0 comments:
Post a Comment