Program for Display Alphabets & Sorted Numbers in Java

Program for Display Alphabets & Sorted Numbers in Java

import java.io.*;
class Alpha
{
    public static void main(String args[])
    {
        String s[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        int n=s.length;
        for(int i=0;i<n;i++)
        {
            System.out.print(s[i]);
        }
        int s1[]={1,54,26,8,32,65};
        int n1=s1.length;

       
        System.out.println(" ");
System.out.println("Sorted Numbers: ");
        for(int i=0;i<n1;i++)
        {
            for(int j=i+1;j<n1;j++)
            {
                if(s1[i] > s1[j])
                {
                    int temp=s1[i];
                    s1[i]=s1[j];
                    s1[j]=temp;
                }
            }
        }
        for(int i=0;i<n1;i++)
        {
            System.out.println(" "+s1[i]);
        }
    }
}

Output

ABCDEFGHIJKLMNOPQRSTUVWXYZ 

Sorted Numbers:

1 8 26 32 54 65

No comments:

Post a Comment

Creating Objects

Creating Objects                  Creating objects means to allocate memory space for all the instance variables of the objects. S...