Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java . util .Scanner;
- class FrequencyofgreatestNumber{
- static void acceptData(){
- String str="";
- System.out.println("Enter the String ::");
- Scanner in = new Scanner(System.in);
- str = in.nextLine();
- int count = 0,max=0;
- char ch[] = str.toCharArray();
- int ch1[] = new int[ch.length];
- int a[] = new int[ch1.length];
- for(int i=0;i<ch.length;i++)
- System.out.print(ch[i]);
- for(int i=0;i<ch.length;i++)
- {
- ch1[i] = java.lang.Integer.parseInt(String.valueOf(str.charAt(i)));
- }
- for(int i=0;i<ch1.length-1;i++)
- {
- if(ch1[i]>ch1[i+1])
- {
- max = ch1[i];
- ch1[i]= ch1[i+1];
- ch1[i+1]=max;
- }
- }
- for(int i=0;i<ch1.length;i++)
- {
- System.out.print(ch1[i]);
- if(ch1[i]==max)
- {
- count++;
- }
- }
- System.out.println("\nFrequency is ::" + count);
- }
- public static void main(String args[]){
- acceptData();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment