Skip to main content

Write a Program in java to sort a list of items in ascending order

Write a Program in java to sort a list of items in ascending order.



class sortList{ 
public static void main(String[] args) { 
int A[]={1,2,6,4,8,7,9}; 
System.out.println("Original List : "); 
printArray(A); 
System.out.println(); 
assendingOrder(A); 
System.out.println("List in ascending order : "); 
printArray(A); 
public static void printArray(int A[]){ 
for(int i=0;i<A.length;i++){ 
System.out.print(A[i]+"\t"); 
public static void assendingOrder(int A[]){ 
int a; 
for(int i=0;i<A.length;i++){ 
for(int j=i;j<A.length;j++){ 
if(A[i]>A[j]){ 
a=A[i]; 
A[i]=A[j]; 
A[j]=a; 
}


OUTPUT:

Original List :
1    2    6    4    8    7    9
List in ascending order :
1    2    4    6    7    8    9



Comments

Popular posts from this blog

DBMS Keys

DBMS Keys KEYS in DBMS is an attribute or set of attributes which helps you to identify a row (tuple) uniquely in a relation(table). They allow you to find the relation between two tables. Keys help you uniquely identify a row in a table by a combination of one or more columns in that table. Key is also helpful for finding unique record or row from the table. Database key is also helpful for finding unique record or row from the table. Example: Employee ID FirstName LastName 11 Andrew Johnson 22 Tom Wood 33 Alex Hale In the above-given example, employee ID is a primary key because it uniquely identifies an employee record. In this table, no other employee can have the same employee ID. Here are some reasons for using sql key in the DBMS system. Keys help you to identify any row of data in a table. In a real-world application, a table could contain thousands of records. Moreover, the records could be duplicated. Keys in RDBMS ensure that you can uniquely identify a table record despite ...

four methods overload these methods

Write a program in java which has the following classes and methods:  Class : OverloadDemo Methods : test() Declare four methods with the same name “test()” and overload these methods class OverloadDemo{  public void test(){  System.out.println("It's a test method for null.");  }  public void test(int n){  System.out.println("It's a test method for displaying the int value "+n);  }  public void test(double d){  System.out.println("It's a test method for displaying the double value "+d);  }  public void test(String s){  System.out.println("It's a test method for displaying the String "+s);  }  }  class overClass{  public static void main(String[] args) {  OverloadDemo old = new OverloadDemo();  old.test();  old.test(12);  old.test(25.35);  old.test("Subham");  }  } OUTPUT: It's a test method for null. It's a test method for displaying the int value 12 It's a test method for ...

Implement Echo client and Echo server using TCP Sockets

Implement Echo client and Echo server using TCP Sockets EchoServer.java import java.net.*; import java.io.*; public class EServer { public static void main(String args[]) { ServerSocket s=null; String line; DataInputStream is; PrintStream ps; Socket c=null; try { s=new ServerSocket(9000); } catch(IOException e) {} try { System.out.println(e); c=s.accept(); is=new DataInputStream(c.getInputStream()); ps=new PrintStream(c.getOutputStream()); while(true) { line=is.readLine(); ps.println(line); }} catch(IOException e) { System.out.println(e); }}} EchoClient.java import java.net.*; import java.io.*; public class EClient { public static void main(String arg[]) { Socket c=null; String line; DataInputStream is,is1; PrintStream os; try { InetAddress ia = InetAddress.getLocalHost(); c=new Socket(ia,9000); } catch(IOException e) {} try { System.out.println(e); os=new PrintStream(c.getOutputStream()); is=new DataInputStream(System.in); is1=new DataInputStream(c.getInputStream()); while(true) { Sys...