Designed a class SortData that contains the method asec() and desc(). | VCMIT

The Method asec() And desc().



INPUT

import java.util.*;
class prac4A
{
Scanner input=new Scanner(System.in);
int num,i;
int arr[];
int temp=0;
public void getdata()
{
System.out.print("Enter the size of array: ");
num=input.nextInt();
arr=new int[num];
System.out.print("Enter the number: ");
for( i=0;i<num;i++)
{
arr[i]=input.nextInt();
}
}
void putdata()
{
System.out.print("Given numbers are: ");
for(i=0;i<num;i++)
{
System.out.println(arr[i]);
}
}
void asce()
{
for(i=0;i<num;i++)
{
for(int j=i+1;j<num;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.print("Ascending order of number are: ");
for(int i=0;i<num;i++)
{
System.out.println(arr[i]);
}
}
void desc()
{
for(i=0;i<num;i++)
{
for(int j=i+1;j<num;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.print("Descending order of number are: ");
for(int i=0;i<num;i++)
{
System.out.println(arr[i]);
}
}
public static void main(String args[])
{
prac4A ob=new prac4A();
ob.getdata();
ob.putdata();
ob.asce();
ob.desc();
}
}

OUTPUT



Disqus Comments
TheWaoFam. Powered by Blogger.

Total Pageviews

Search This Blog

  • ()

Random Posts

randomposts

Recent Posts

recentposts

Footer Link

Connected

Facebook

banner image

Most Recent

Contact Form

Categories

There are many variations of passages of Lorem Ipsum available.

About Me

Hi there, I’m Amanda – a girl love fashion and love to express herself with her own sense of style.

Trending