You are given a string consisting of n lowercase Latin letters. You must find the count of number of larger alphabets for every character of the string (according to lexicographical order).

 /* Counting no.of larger alphabets for every character of the string */


import java.io.*;

import java.util.*;

class Alpha_2B

{

    public static void main(String args[])

    {

String s1;

int i,j,c,n;

int a[] = new int[20];

Scanner s = new Scanner(System.in);

System.out.println("Enter  a string : ");

s1 = s.next();

n = s1.length();

char t;

char ch[] = s1.toCharArray();   // Converting String to charecter array

// Sorting charecters

for(i=0;i<n;i++)

{

   for(j=0;j<n;j++)

   {

if(ch[i] < ch[j])

{

   t = ch[i];

   ch[i]= ch[j];

   ch[j] = t;

}

   }

}


// Counting charecter 

for(i=0;i<n;i++)

{

   c=0;

   for(j=0;j<n;j++)

   {

if(ch[i] < ch[j])

{

   c++;

}

   }

   a[i] = c;

}


// Printing sorted charecters

System.out.println("Sorted charecters and no.of large alphabets are :");

for(i=0;i<n;i++)

{

    System.out.print(ch[i]);

}

System.out.print("\n");

// Printing number of large alphabets

for(i=0;i<n;i++)

{

    System.out.print(a[i]);

}

    }

}


Comments

Popular posts from this blog

Design GUI to handle Choice Control event.

Write a Java program that reads an integer number (between 1 and 255) from the user and prints the binary representation of the number. The answer should be printed as a String. Note: The output displayed should contain 8 digits and should be padded with leading 0s(zeros), in case the returned String contains less than 8 characters. For example, if the user enters the value 16, then the output should be 00010000 and if the user enters the value 100, the output should be 01100100 (Hint : You may use String.format() method for the expected output)