Вы находитесь на странице: 1из 5

ASSIGHNMENT

Name Muhammad Sohaib


REG# BSSE-02163042
Section “ S ”
Subject JAVA
Progarm-1st:

package ascending.oredr;

/**
*
* @author bsse02163042
*/
public class AscendingOredr
{

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
int[] z={3,2,1,5,6};
int temp = 0;
int n = 5;
for(int s=0; s < n; s++)
{
for(int j=1; j < (n-s); j++)
{
if(z[j-1] > z[j])
{
temp = z[j-1];
z[j-1] = z[j];
z[j] = temp;
}
}
}
System.out.println("The ascending order:");
for(int i=0;i<5;i++)
{
System.out.println(z[i]+" ");
}
}

Output:

Progarm-2nd:

package descending.order;

/**
*
* @author bsse02163042
*/
public class DescendingOrder
{

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
int[] z={6,5,1,2,3};
int temp = 0;
int n = 5;
for(int x=0; x < n; x++)
{
for(int j=1; j < (n-x); j++)
{
if(z[j-1] < z[j])
{
//swap elements
temp = z[j-1];
z[j-1] = z[j];
z[j] = temp;

}
}
System.out.println("The decending order:");
for(int i=0;i<5;i++)
{
System.out.println(z[i]+" ");
}
}
}

Output:

Вам также может понравиться