codeparrot/xlcost-text-to-code huggingface dataset:
Remove the forbidden strings | Java program to remove forbidden strings ; number of forbidden strings ; original string ; forbidden strings ; to store original string as character array ; letter to replace and occur max number of times ; pre [ ] keeps record of the characters of w that need to be changed ; Function to check if the particular substring is present in w at position ; If length of substring from this position is greater than length of w then return ; n and n1 are used to check for substring without considering the case of the letters in w by comparing the difference of ASCII values ; If same == true then it means a substring was found starting at position therefore all characters from position to length of substring found need to be changed therefore they need to be marked ; Function performing calculations . ; To verify if any substring is starting from index i ; Modifying the string w according to th rules ; This condition checks if w [ i ] = upper ( letter ) ; This condition checks if w [ i ] is any lowercase letter apart from letter . If true replace it with letter ; This condition checks if w [ i ] is any uppercase letter apart from letter . If true then replace it with upper ( letter ) . ; Driver function for the program
import java . io . * ; class rtf { public static int n ; public static String z ; public static String s [ ] = new String [ 100 ] ; public static char w [ ] ; public static char letter ; public static boolean pre [ ] = new boolean [ 100 ] ; public static void verify ( int position , int index ) { int l = z . length ( ) ; int k = s [ index ] . length ( ) ; if ( position + k > l ) return ; boolean same = true ; for ( int i = position ; i < position + k ; i ++ ) { int n , n1 ; char ch = w [ i ] ; char ch1 = s [ index ] . charAt ( i - position ) ; if ( ch >= ' a ' && ch <= ' z ' ) n = ch - ' a ' ; else n = ch - ' A ' ; if ( ch1 >= ' a ' && ch1 <= ' z ' ) n1 = ch1 - ' a ' ; else n1 = ch1 - ' A ' ; if ( n != n1 ) same = false ; } if ( same == true ) { for ( int i = position ; i < position + k ; i ++ ) pre [ i ] = true ; return ; } } public static void solve ( ) { w = z . toCharArray ( ) ; letter = ' d ' ; int l = z . length ( ) ; int p = letter - ' a ' ; for ( int i = 0 ; i < 100 ; i ++ ) pre [ i ] = false ; for ( int i = 0 ; i < l ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) verify ( i , j ) ; } for ( int i = 0 ; i < l ; i ++ ) { if ( pre [ i ] == true ) { if ( w [ i ] == letter ) w [ i ] = ( letter == ' a ' ) ? ' b ' : ' a ' ; else if ( w [ i ] == ( char ) ( ( int ) ' A ' + p ) ) w [ i ] = ( letter == ' a ' ) ? ' B ' : ' A ' ; else if ( w [ i ] >= ' a ' && w [ i ] <= ' z ' ) w [ i ] = letter ; else if ( w [ i ] >= ' A ' && w [ i ] <= ' Z ' ) w [ i ] = ( char ) ( ( int ) ' A ' + p ) ; } } System . out . println ( w ) ; } public static void main ( String args [ ] ) { n = 3 ; s [ 0 ] = " etr " ; s [ 1 ] = " ed " ; s [ 2 ] = " ied " ; z = " PEtrUnited " ; solve ( ) ; } }
Round the given number to nearest multiple of 10 | Java Code for Round the given number to nearest multiple of 10 ; function to round the number ; Smaller multiple ; Larger multiple ; Return of closest of two ; Driver program to test above function
import java . util . * ; class GFG { static int round ( int n ) { int a = ( n / 10 ) * 10 ; int b = a + 10 ; return ( n - a > b - n ) ? b : a ; } public static void main ( String [ ] args ) { int n = 4722 ; System . out . println ( round ( n ) ) ; } }
Breaking a number such that first part is integral division of second by a power of 10 | Java program to count ways to divide a String in two parts a and b such that b / pow ( 10 , p ) == a ; subString representing int a ; no of digits in a ; consider only most significant l1 characters of remaining String for int b ; if any of a or b contains leading 0 s discard this combination ; if both are equal ; Driver Code
import java . util . * ; class GFG { static int calculate ( String N ) { int len = N . length ( ) ; int l = ( len ) / 2 ; int count = 0 ; for ( int i = 1 ; i <= l ; i ++ ) { String s = N . substring ( 0 , i ) ; int l1 = s . length ( ) ; String t = N . substring ( i , l1 + i ) ; if ( s . charAt ( 0 ) == '0' || t . charAt ( 0 ) == '0' ) continue ; if ( s . compareTo ( t ) == 0 ) count ++ ; } return count ; } public static void main ( String [ ] args ) { String N = "2202200" ; System . out . print ( calculate ( N ) ) ; } }
Number of subsequences as " ab " in a string repeated K times | Java code to find number of subsequences of " ab " in the string S which is repeated K times . ; Count of ' a ' s ; Count of ' b ' s ; occurrence of " ab " s in string S ; Add following two : 1 ) K * ( Occurrences of " ab " in single string ) 2 ) a is from one string and b is from other . ; Driver code
import java . io . * ; class GFG { static int countOccurrences ( String s , int K ) { int n = s . length ( ) ; int C = 0 , c1 = 0 , c2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' a ' ) c1 ++ ; if ( s . charAt ( i ) == ' b ' ) { c2 ++ ; C += c1 ; } } return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ; } public static void main ( String [ ] args ) { String S = " abcb " ; int k = 2 ; System . out . println ( countOccurrences ( S , k ) ) ; } }
Program to check Strength of Password | Java implementation fo the above approach ; Checking lower alphabet in string ; Strength of password ; Driver Code
import java . io . * ; import java . util . * ; class GFG { public static void printStrongNess ( String input ) { int n = input . length ( ) ; boolean hasLower = false , hasUpper = false , hasDigit = false , specialChar = false ; Set < Character > set = new HashSet < Character > ( Arrays . asList ( ' ! ' , ' @ ' , ' # ' , ' $ ' , ' % ' , ' ^ ' , ' & ' , ' * ' , ' ( ' , ' ) ' , ' - ' , ' + ' ) ) ; for ( char i : input . toCharArray ( ) ) { if ( Character . isLowerCase ( i ) ) hasLower = true ; if ( Character . isUpperCase ( i ) ) hasUpper = true ; if ( Character . isDigit ( i ) ) hasDigit = true ; if ( set . contains ( i ) ) specialChar = true ; } System . out . print ( " Strength ▁ of ▁ password : - ▁ " ) ; if ( hasDigit && hasLower && hasUpper && specialChar && ( n >= 8 ) ) System . out . print ( " ▁ Strong " ) ; else if ( ( hasLower hasUpper specialChar ) && ( n >= 6 ) ) System . out . print ( " ▁ Moderate " ) ; else System . out . print ( " ▁ Weak " ) ; } public static void main ( String [ ] args ) { String input = " GeeksforGeeks ! @12" ; printStrongNess ( input ) ; } }
String with k distinct characters and no same characters adjacent | Java program to construct a n length string with k distinct characters such that no two same characters are adjacent . ; Function to find a string of length n with k distinct characters . ; Initialize result with first k Latin letters ; Fill remaining n - k letters by repeating k letters again and again . ; Driver code
import java . io . * ; public class GFG { static String findString ( int n , int k ) { String res = " " ; for ( int i = 0 ; i < k ; i ++ ) res = res + ( char ) ( ' a ' + i ) ; int count = 0 ; for ( int i = 0 ; i < n - k ; i ++ ) { res = res + ( char ) ( ' a ' + count ) ; count ++ ; if ( count == k ) count = 0 ; } return res ; } static public void main ( String [ ] args ) { int n = 5 , k = 2 ; System . out . println ( findString ( n , k ) ) ; } }
Program for credit card number validation | Java program to check if a given credit card is valid or not . ; Main Method ; Return true if the card number is valid ; Get the result from Step 2 ; Return this number if it is a single digit , otherwise , return the sum of the two digits ; Return sum of odd - place digits in number ; Return true if the digit d is a prefix for number ; Return the number of digits in d ; Return the first k number of digits from number . If the number of digits in number is less than k , return number .
import java . util . Scanner ; public class CreditCard { public static void main ( String [ ] args ) { long number = 5196081888500645L ; System . out . println ( number + " ▁ is ▁ " + ( isValid ( number ) ? " valid " : " invalid " ) ) ; } public static boolean isValid ( long number ) { return ( getSize ( number ) >= 13 && getSize ( number ) <= 16 ) && ( prefixMatched ( number , 4 ) || prefixMatched ( number , 5 ) || prefixMatched ( number , 37 ) || prefixMatched ( number , 6 ) ) && ( ( sumOfDoubleEvenPlace ( number ) + sumOfOddPlace ( number ) ) % 10 == 0 ) ; } public static int sumOfDoubleEvenPlace ( long number ) { int sum = 0 ; String num = number + " " ; for ( int i = getSize ( number ) - 2 ; i >= 0 ; i -= 2 ) sum += getDigit ( Integer . parseInt ( num . charAt ( i ) + " " ) * 2 ) ; return sum ; } public static int getDigit ( int number ) { if ( number < 9 ) return number ; return number / 10 + number % 10 ; } public static int sumOfOddPlace ( long number ) { int sum = 0 ; String num = number + " " ; for ( int i = getSize ( number ) - 1 ; i >= 0 ; i -= 2 ) sum += Integer . parseInt ( num . charAt ( i ) + " " ) ; return sum ; } public static boolean prefixMatched ( long number , int d ) { return getPrefix ( number , getSize ( d ) ) == d ; } public static int getSize ( long d ) { String num = d + " " ; return num . length ( ) ; } public static long getPrefix ( long number , int k ) { if ( getSize ( number ) > k ) { String num = number + " " ; return Long . parseLong ( num . substring ( 0 , k ) ) ; } return number ; } }
Find substrings that contain all vowels | Java program to find all substring that contain all vowels ; Returns true if x is vowel . ; Function to check whether a character is vowel or not ; Function to FindSubstrings of string ; To store vowels ; If current character is vowel then insert into hash , ; If all vowels are present in current substring ; Driver Code
import java . util . HashSet ; public class GFG { static boolean isVowel ( char x ) { return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } static void findSubstring ( String str ) { HashSet < Character > hash = new HashSet < Character > ( ) ; int start = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( isVowel ( str . charAt ( i ) ) == true ) { hash . add ( str . charAt ( i ) ) ; if ( hash . size ( ) == 5 ) System . out . print ( str . substring ( start , i + 1 ) + " ▁ " ) ; } else { start = i + 1 ; hash . clear ( ) ; } } } public static void main ( String [ ] args ) { String str = " aeoibsddaeiouudb " ; findSubstring ( str ) ; } }
Concatenated string with uncommon characters of two strings | Java program Find concatenated string with uncommon characters of given strings ; Result ; creating a hashMap to add characters in string s2 ; Find characters of s1 that are not present in s2 and append to result ; Find characters of s2 that are not present in s1 . ; Driver code
import java . util . * ; import java . lang . * ; import java . io . * ; class gfg { public static String concatenatedString ( String s1 , String s2 ) { String res = " " ; int i ; HashMap < Character , Integer > m = new HashMap < Character , Integer > ( ) ; for ( i = 0 ; i < s2 . length ( ) ; i ++ ) m . put ( s2 . charAt ( i ) , 1 ) ; for ( i = 0 ; i < s1 . length ( ) ; i ++ ) if ( ! m . containsKey ( s1 . charAt ( i ) ) ) res += s1 . charAt ( i ) ; else m . put ( s1 . charAt ( i ) , 2 ) ; for ( i = 0 ; i < s2 . length ( ) ; i ++ ) if ( m . get ( s2 . charAt ( i ) ) == 1 ) res += s2 . charAt ( i ) ; return res ; } public static void main ( String [ ] args ) { String s1 = " abcs " ; String s2 = " cxzca " ; System . out . println ( concatenatedString ( s1 , s2 ) ) ; } }
Count All Palindrome Sub | Java Program to count palindrome substring in a string ; Method which return count palindrome substring ; Iterate the loop twice ; Get each substring ; If length is greater than or equal to two Check for palindrome ; Use StringBuffer class to reverse the string ; Compare substring wih reverse of substring ; return the count ; Driver Code ; Declare and initialize the string ; Call the method
public class PalindromeSubstring { static int countPS ( String str ) { String temp = " " ; StringBuffer stf ; int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { for ( int j = i + 1 ; j <= str . length ( ) ; j ++ ) { temp = str . substring ( i , j ) ; if ( temp . length ( ) >= 2 ) { stf = new StringBuffer ( temp ) ; stf . reverse ( ) ; if ( stf . toString ( ) . compareTo ( temp ) == 0 ) count ++ ; } } } return count ; } public static void main ( String args [ ] ) throws Exception { String str = " abbaeae " ; System . out . println ( countPS ( str ) ) ; }
Print all Subsequences of String which Start with Vowel and End with Consonant . | Java Program to generate all the subsequence starting with vowel and ending with consonant . ; Set to store all the subsequences ; It computes all the possible substring that starts with vowel and end with consonent ; iterate over the entire string ; test ith character for vowel ; if the ith character is vowel iterate from end of the string and check for consonant . ; test jth character for consonant . ; once we get a consonant add it to the hashset ; drop each character of the substring and recur to generate all subsequence of the substring ; Utility method to check vowel ; Utility method to check consonant ; Driver code
import java . util . HashSet ; public class Subsequence { static HashSet < String > st = new HashSet < > ( ) ; static void subsequence ( String str ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( isVowel ( str . charAt ( i ) ) ) { for ( int j = ( str . length ( ) - 1 ) ; j >= i ; j -- ) { if ( isConsonant ( str . charAt ( ( j ) ) ) ) { String str_sub = str . substring ( i , j + 1 ) ; st . add ( str_sub ) ; for ( int k = 1 ; k < str_sub . length ( ) - 1 ; k ++ ) { StringBuffer sb = new StringBuffer ( str_sub ) ; sb . deleteCharAt ( k ) ; subsequence ( sb . toString ( ) ) ; } } } } } } static boolean isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static boolean isConsonant ( char c ) { return ! isVowel ( c ) ; } public static void main ( String [ ] args ) { String s = " xabcef " ; subsequence ( s ) ; System . out . println ( st ) ; } }
Null Cipher | Java program to decode NULL CIPHER ; Function to decode the message . ; Store the decoded string ; found variable is used to tell that the encoded encoded character is found in that particular word . ; Set found variable to false whenever we find whitespace , meaning that encoded character for new word is not found ; Driver Code
class GFG { static String decode ( String str ) { String res = " " ; boolean found = false ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ' ▁ ' ) { found = false ; continue ; } if ( ! found ) { if ( ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) || ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) ) { res += Character . toString ( str . charAt ( i ) ) ; found = true ; } } } return res . toLowerCase ( ) ; } public static void main ( String [ ] args ) { String in ; in = " A ▁ Step ▁ by ▁ Step ▁ Guide ▁ for ▁ Placement ▁ Preparation ▁ by ▁ GeeksforGeeks " ; System . out . println ( " Enciphered ▁ Message : ▁ " + decode ( in ) ) ; } }
Program to count vowels in a string ( Iterative and Recursive ) | Recursive Java program to count the total number of vowels using recursion ; Function to check the Vowel ; to count total number of vowel from 0 to n ; Main Calling Function ; string object ; Total numbers of Vowel
public class GFG { static int isVowel ( char ch ) { ch = Character . toUpperCase ( ch ) ; if ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) return 1 ; else return 0 ; } static int countVowels ( String str , int n ) { if ( n == 1 ) return isVowel ( str . charAt ( n - 1 ) ) ; return countVowels ( str , n - 1 ) + isVowel ( str . charAt ( n - 1 ) ) ; } public static void main ( String args [ ] ) { String str = " abc ▁ de " ; System . out . println ( countVowels ( str , str . length ( ) ) ) ; } }
Smallest window that contains all characters of string itself | Java program to find the smallest window containing all characters of a pattern . ; Function to find smallest window containing all distinct characters ; Count all distinct characters . ; Now follow the algorithm discussed in below ; Driver code
import java . io . * ; import java . util . * ; class GFG { public static String findSubString ( String str ) { int n = str . length ( ) ; int dist_count = 0 ; HashMap < Character , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( str . charAt ( i ) ) ) { Integer a = mp . get ( str . charAt ( i ) ) ; mp . put ( str . charAt ( i ) , a + 1 ) ; } else { mp . put ( str . charAt ( i ) , 1 ) ; } } dist_count = mp . size ( ) ; int size = Integer . MAX_VALUE ; String res = " " ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; int visited [ ] = new int [ 256 ] ; for ( int j = 0 ; j < 256 ; j ++ ) visited [ j ] = 0 ; String sub_str = " " ; for ( int j = i ; j < n ; j ++ ) { if ( visited [ str . charAt ( j ) ] == 0 ) { count ++ ; visited [ str . charAt ( j ) ] = 1 ; } sub_str += str . charAt ( j ) ; if ( count == dist_count ) break ; } if ( sub_str . length ( ) < size && count == dist_count ) { res = sub_str ; size = res . length ( ) ; } } return res ; } public static void main ( String [ ] args ) { String str = " aabcbcdbca " ; System . out . println ( " Smallest ▁ window ▁ containing ▁ all ▁ distinct " + " ▁ characters ▁ is : ▁ " + findSubString ( str ) ) ; } }
Generate all rotations of a given string | A simple Java program to generate all rotations of a given string ; Print all the rotated string . ; Concatenate str with itself ; Print all substrings of size n . Note that size of sb is 2 n ; Driver method
class Test { static void printRotatedString ( String str ) { int n = str . length ( ) ; StringBuffer sb = new StringBuffer ( str ) ; sb . append ( str ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j != n ; j ++ ) System . out . print ( sb . charAt ( i + j ) ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { String str = new String ( " geeks " ) ; printRotatedString ( str ) ; } }
Check if frequency of all characters can become same by one removal | Java program to get same frequency character string by removal of at most one char ; Utility method to get index of character ch in lower alphabet characters ; Returns true if all non - zero elements values are same ; get first non - zero element ; check equality of each element with variable same ; Returns true if we can make all character frequencies same ; fill frequency array ; if all frequencies are same , then return true ; Try decreasing frequency of all character by one and then check all equality of all non - zero frequencies ; Check character only if it occurs in str ; Driver code to test above methods
public class GFG { static final int M = 26 ; static int getIdx ( char ch ) { return ( ch - ' a ' ) ; } static boolean allSame ( int freq [ ] , int N ) { int same = 0 ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( freq [ i ] > 0 ) { same = freq [ i ] ; break ; } } for ( int j = i + 1 ; j < N ; j ++ ) if ( freq [ j ] > 0 && freq [ j ] != same ) return false ; return true ; } static boolean possibleSameCharFreqByOneRemoval ( String str ) { int l = str . length ( ) ; int [ ] freq = new int [ M ] ; for ( int i = 0 ; i < l ; i ++ ) freq [ getIdx ( str . charAt ( i ) ) ] ++ ; if ( allSame ( freq , M ) ) return true ; for ( char c = ' a ' ; c <= ' z ' ; c ++ ) { int i = getIdx ( c ) ; if ( freq [ i ] > 0 ) { freq [ i ] -- ; if ( allSame ( freq , M ) ) return true ; freq [ i ] ++ ; } } return false ; } public static void main ( String args [ ] ) { String str = " xyyzz " ; if ( possibleSameCharFreqByOneRemoval ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Check if a large number is divisible by 11 or not | Java program to find if a number is divisible by 11 or not ; Function to find that number divisible by 11 or not ; Compute sum of even and odd digit sums ; When i is even , position of digit is odd ; Check its difference is divisible by 11 or not ; main function
class IsDivisible { static boolean check ( String str ) { int n = str . length ( ) ; int oddDigSum = 0 , evenDigSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) oddDigSum += ( str . charAt ( i ) - '0' ) ; else evenDigSum += ( str . charAt ( i ) - '0' ) ; } return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ; } public static void main ( String [ ] args ) { String str = "76945" ; if ( check ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Hamming Distance between two strings | Java program to find hamming distance b / w two string ; function to calculate Hamming distance ; Driver code ; function call
class GFG { static int hammingDist ( String str1 , String str2 ) { int i = 0 , count = 0 ; while ( i < str1 . length ( ) ) { if ( str1 . charAt ( i ) != str2 . charAt ( i ) ) count ++ ; i ++ ; } return count ; } public static void main ( String [ ] args ) { String str1 = " geekspractice " ; String str2 = " nerdspractise " ; System . out . println ( hammingDist ( str1 , str2 ) ) ; } }
Check if two strings are k | Java program to check if two strings are k anagram or not . ; Function to check that string is k - anagram or not ; If both strings are not of equal length then return false ; Store the occurrence of all characters in a hash_array ; Count number of characters that are different in both strings ; Return true if count is less than or equal to k ; Driver code
public class GFG { static final int MAX_CHAR = 26 ; static boolean arekAnagrams ( String str1 , String str2 , int k ) { int n = str1 . length ( ) ; if ( str2 . length ( ) != n ) return false ; int [ ] count1 = new int [ MAX_CHAR ] ; int [ ] count2 = new int [ MAX_CHAR ] ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( count1 [ i ] > count2 [ i ] ) count = count + Math . abs ( count1 [ i ] - count2 [ i ] ) ; return ( count <= k ) ; } public static void main ( String args [ ] ) { String str1 = " anagram " ; String str2 = " grammar " ; int k = 2 ; if ( arekAnagrams ( str1 , str2 , k ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Remove spaces from a given string | An efficient Java program to remove all spaces from a string ; Function to remove all spaces from a given string ; To keep track of non - space character count ; Traverse the given string . If current character is not space , then place it at index ' count + + ' ; str [ count ++ ] = str [ i ] ; here count is incremented ; Driver code
class GFG { static int removeSpaces ( char [ ] str ) { int count = 0 ; for ( int i = 0 ; i < str . length ; i ++ ) if ( str [ i ] != ' ▁ ' ) return count ; } public static void main ( String [ ] args ) { char str [ ] = " g ▁ eeks ▁ for ▁ ge ▁ eeks ▁ " . toCharArray ( ) ; int i = removeSpaces ( str ) ; System . out . println ( String . valueOf ( str ) . subSequence ( 0 , i ) ) ; } }
Given a binary string , count number of substrings that start and end with 1. | A O ( n ) C ++ program to count number of substrings starting and ending with 1 ; Traverse input string and count of 1 's in it ; Return count of possible pairs among m 1 's ; Driver program to test the above function
class CountSubString { int countSubStr ( char str [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '1' ) m ++ ; } return m * ( m - 1 ) / 2 ; } public static void main ( String [ ] args ) { CountSubString count = new CountSubString ( ) ; String string = "00100101" ; char str [ ] = string . toCharArray ( ) ; int n = str . length ; System . out . println ( count . countSubStr ( str , n ) ) ; } }