Which is the function to display a group of characters in java

Answers (1)

// Java program to print all occurrences of every character 
// together. 

class Test 
 
    // Since only lower case characters are there 
    static final int MAX_CHAR = 26; 
    
    // Method to print the string 
    static void printGrouped(String str) 
     
        int n = str.length(); 
    
        // Initialize counts of all characters as 0 
        int count[] = new int[MAX_CHAR]; 
    
        // Count occurrences of all characters in string 
        for (int i = 0 ; i < n ; i++) 
            count[str.charAt(i)-'a']++; 
    
        // Starts traversing the string 
        for (int i = 0; i < n ; i++) 
         
            // Print the character till its count in 
            // hash array 
            while (count[str.charAt(i)-'a']!=0) 
                System.out.print(str.charAt(i)); 
                count[str.charAt(i)-'a']--; 
             
    
            // Make this character's count value as 0. 
            count[str.charAt(i)-'a'] = 0; 
         
     
    
    // Driver method 
    public static void main(String args[]) 
     
        String str = new String("geeksforgeeks"); 
        
        printGrouped(str); 
     
 
 

Most Viewed Questions

Preparation Products

Knockout NEET May 2023 (Easy Installments)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 5499/-
Buy Now
Knockout JEE Main April 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout NEET Aug 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout JEE Main May 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Knockout NEET Aug 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Boost your Preparation for JEE Main with our Foundation Course
 
Exams
Articles
Questions