Print all 3 digit repeating numbers in a very large number | Java program to print 3 digit repeating numbers ; function to print 3 digit repeating numbers ; Hashmap to store the frequency of a 3 digit number ; first three digit number ; if key already exists increase value by 1 ; Output the three digit numbers with frequency > 1 ; Driver Code ; Input string ; Calling Function
import java . util . * ; import java . lang . * ; public class GFG { static void printNum ( String s ) { int i = 0 , j = 0 , val = 0 ; LinkedHashMap < Integer , Integer > hm = new LinkedHashMap < > ( ) ; val = ( s . charAt ( 0 ) - '0' ) * 100 + ( s . charAt ( 1 ) - '0' ) * 10 + ( s . charAt ( 2 ) - '0' ) ; hm . put ( val , 1 ) ; for ( i = 3 ; i < s . length ( ) ; i ++ ) { val = ( val % 100 ) * 10 + s . charAt ( i ) - '0' ; if ( hm . containsKey ( val ) ) { hm . put ( val , hm . get ( val ) + 1 ) ; } else { hm . put ( val , 1 ) ; } } for ( Map . Entry < Integer , Integer > en : hm . entrySet ( ) ) { int key = en . getKey ( ) ; int value = en . getValue ( ) ; if ( value > 1 ) System . out . println ( key + " ▁ - ▁ " + value + " ▁ times " ) ; } } public static void main ( String args [ ] ) { String input = "123412345123456" ; printNum ( input ) ; } }