codeparrot/xlcost-text-to-code huggingface dataset:
Partition problem | DP | A dynamic programming based Java program for partition problem ; Returns true if arr [ ] can be partitioned in two subsets of equal sum , otherwise false ; Calculate sum of all elements ; initialize top row as true ; initialize leftmost column , except part [ 0 ] [ 0 ] , as 0 ; Fill the partition table in bottom up manner ; uncomment this part to print table ; Driver code ; Function call
import java . io . * ; class Partition { static boolean findPartition ( int arr [ ] , int n ) { int sum = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; boolean part [ ] [ ] = new boolean [ sum / 2 + 1 ] [ n + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) part [ 0 ] [ i ] = true ; for ( i = 1 ; i <= sum / 2 ; i ++ ) part [ i ] [ 0 ] = false ; for ( i = 1 ; i <= sum / 2 ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { part [ i ] [ j ] = part [ i ] [ j - 1 ] ; if ( i >= arr [ j - 1 ] ) part [ i ] [ j ] = part [ i ] [ j ] || part [ i - arr [ j - 1 ] ] [ j - 1 ] ; } } return part [ sum / 2 ] [ n ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 1 , 1 , 2 , 2 , 1 } ; int n = arr . length ; if ( findPartition ( arr , n ) == true ) System . out . println ( " Can ▁ be ▁ divided ▁ into ▁ two ▁ " " subsets ▁ of ▁ equal ▁ sum " ) ; else System . out . println ( " Can ▁ not ▁ be ▁ divided ▁ into " " ▁ two ▁ subsets ▁ of ▁ equal ▁ sum " ) ; } }
Minimum number of Appends of X or Y characters from the end to the front required to obtain given string | Java program for the above approach ; Function to find the minimum operations required to get the given string after appending m or n characters from the end to the front of the string in each operation ; Store the original string ; Stores the count of operations ; Traverse the string ; Cut m letters from end ; Add cut m letters to beginning ; Update j ; Check if strings are the same ; Cut n letters from end ; Add cut n letters to beginning ; Update j ; Check if strings are the same ; Update the turn ; Driver Code ; Given string S ; Function Call
import java . io . * ; import java . util . * ; class GFG { static void minimumOperations ( String orig_str , int m , int n ) { String orig = orig_str ; int turn = 1 ; int j = 1 ; for ( int i = 0 ; i < orig_str . length ( ) ; i ++ ) { String m_cut = orig_str . substring ( orig_str . length ( ) - m ) ; orig_str = orig_str . substring ( 0 , orig_str . length ( ) - m ) ; orig_str = m_cut + orig_str ; j = j + 1 ; if ( ! orig . equals ( orig_str ) ) { turn = turn + 1 ; String n_cut = orig_str . substring ( orig_str . length ( ) - n ) ; orig_str = orig_str . substring ( 0 , orig_str . length ( ) - n ) ; orig_str = n_cut + orig_str ; j = j + 1 ; } if ( orig . equals ( orig_str ) ) { break ; } turn = turn + 1 ; } System . out . println ( turn ) ; } public static void main ( String [ ] args ) { String S = " GeeksforGeeks " ; int X = 5 , Y = 3 ; minimumOperations ( S , X , Y ) ; } }
Minimum rotations required to get the same String | Set | Java implementation of the above approach ; Prints occurrences of txt [ ] in pat [ ] ; Create lps [ ] that will hold the longest prefix suffix values for pattern ; Preprocess the pattern ( calculate lps [ ] array ) ; Index for txt [ ] , index for pat [ ] ; Mismatch after j matches ; Do not match lps [ 0. . lps [ j - 1 ] ] characters , they will match anyway ; Fills lps [ ] for given pattern pat [ 0. . M - 1 ] ; Length of the previous longest prefix suffix ; lps [ 0 ] is always 0 ; The loop calculates lps [ i ] for i = 1 to M - 1 ; ( pat [ i ] != pat [ len ] ) ; This is tricky . Consider the example . AAACAAAA and i = 7. The idea is similar to search step . ; Returns count of rotations to get the same String back ; Form a String excluding the first character and concatenating the String at the end ; Convert the String to character array ; Use the KMP search algorithm to find it in O ( N ) time ; Driver code
class GFG { static int KMPSearch ( char [ ] pat , char [ ] txt ) { int M = pat . length ; int N = txt . length ; int lps [ ] = new int [ M ] ; computeLPSArray ( pat , M , lps ) ; int i = 0 ; int j = 0 ; while ( i < N ) { if ( pat [ j ] == txt [ i ] ) { j ++ ; i ++ ; } if ( j == M ) { return i - j + 1 ; } else if ( i < N && pat [ j ] != txt [ i ] ) { if ( j != 0 ) j = lps [ j - 1 ] ; else i = i + 1 ; } } return 0 ; } static void computeLPSArray ( char [ ] pat , int M , int [ ] lps ) { int len = 0 ; lps [ 0 ] = 0 ; int i = 1 ; while ( i < M ) { if ( pat [ i ] == pat [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } } static int countRotations ( String s ) { String s1 = s . substring ( 1 , s . length ( ) - 1 ) + s ; char [ ] pat = s . toCharArray ( ) ; char [ ] text = s1 . toCharArray ( ) ; return 1 + KMPSearch ( pat , text ) ; } public static void main ( String [ ] args ) { String s1 = " geeks " ; System . out . print ( countRotations ( s1 ) ) ; } }
DFA for Strings not ending with " THE " | Java program to implement DFS that accepts all string that do not end with " THE " ; dfa tells the number associated with the present state ; This function is for the starting state ( zeroth ) of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) ; This function is for the first state of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) ; On receiving ' H ' or ' h ' goto second state ( 2 ) ; else goto starting state ( 0 ) ; This function is for the second state of DFA ; On receiving ' E ' or ' e ' goto third state ( 3 ) else goto starting state ( 0 ) ; This function is for the third state of DFA ; On receiving ' T ' or ' t ' goto first state ( 1 ) else goto starting state ( 0 ) ; store length of string ; Driver code
import java . util . * ; class GFG { static int dfa = 0 ; static void start ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; } static void state1 ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; else if ( c == ' h ' c == ' H ' ) dfa = 2 ; else dfa = 0 ; } static void state2 ( char c ) { if ( c == ' e ' c == ' E ' ) dfa = 3 ; else dfa = 0 ; } static void state3 ( char c ) { if ( c == ' t ' c == ' T ' ) dfa = 1 ; else dfa = 0 ; } static boolean isAccepted ( char str [ ] ) { int len = str . length ; for ( int i = 0 ; i < len ; i ++ ) { if ( dfa == 0 ) start ( str [ i ] ) ; else if ( dfa == 1 ) state1 ( str [ i ] ) ; else if ( dfa == 2 ) state2 ( str [ i ] ) ; else state3 ( str [ i ] ) ; } return ( dfa != 3 ) ; } public static void main ( String [ ] args ) { char str [ ] = " forTHEgeeks " . toCharArray ( ) ; if ( isAccepted ( str ) == true ) System . out . println ( "ACCEPTEDNEW_LINE"); else System . out . println ( "NOT ACCEPTEDNEW_LINE"); } }
Check if one string can be converted to another | Java implementation of the above approach . ; Function for find from Disjoint set algorithm ; Function for the union from Disjoint set algorithm ; Function to check if one String can be converted to another . ; All the characters are checked whether it 's either not replaced or replaced  by a similar character using a map. ; To check if there are cycles . If yes , then they are not convertible . Else , they are convertible . ; Function to initialize parent array for union and find algorithm . ; Driver code
import java . util . * ; class GFG { static int [ ] parent = new int [ 26 ] ; static int find ( int x ) { if ( x != parent [ x ] ) return parent [ x ] = find ( parent [ x ] ) ; return x ; } static void join ( int x , int y ) { int px = find ( x ) ; int pz = find ( y ) ; if ( px != pz ) { parent [ pz ] = px ; } } static boolean convertible ( String s1 , String s2 ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( ! mp . containsKey ( s1 . charAt ( i ) - ' a ' ) ) { mp . put ( s1 . charAt ( i ) - ' a ' , s2 . charAt ( i ) - ' a ' ) ; } else { if ( mp . get ( s1 . charAt ( i ) - ' a ' ) != s2 . charAt ( i ) - ' a ' ) return false ; } } for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { if ( it . getKey ( ) == it . getValue ( ) ) continue ; else { if ( find ( it . getKey ( ) ) == find ( it . getValue ( ) ) ) return false ; else join ( it . getKey ( ) , it . getValue ( ) ) ; } } return true ; } static void initialize ( ) { for ( int i = 0 ; i < 26 ; i ++ ) { parent [ i ] = i ; } } public static void main ( String [ ] args ) { String s1 , s2 ; s1 = " abbcaa " ; s2 = " bccdbb " ; initialize ( ) ; if ( convertible ( s1 , s2 ) ) System . out . print ( " Yes " + "NEW_LINE"); else System . out . print ( " No " + "NEW_LINE"); } }
Print characters having prime frequencies in order of occurrence | Java implementation of the approach ; Function to create Sieve to check primes ; false here indicates that it is not prime ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p , set them to non - prime ; Function to print the prime frequency characters in the order of their occurrence ; Function to create Sieve to check primes ; To store the frequency of each of the character of the string ; Initialize all elements of freq [ ] to 0 ; Update the frequency of each character ; Traverse str character by character ; If frequency of current character is prime ; Driver code
class GFG { static int SIZE = 26 ; static void SieveOfEratosthenes ( boolean [ ] prime , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i < p_size ; i += p ) prime [ i ] = false ; } } } static void printChar ( String str , int n ) { boolean [ ] prime = new boolean [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; SieveOfEratosthenes ( prime , str . length ( ) + 1 ) ; int [ ] freq = new int [ SIZE ] ; for ( int i = 0 ; i < SIZE ; i ++ ) freq [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) freq [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ freq [ str . charAt ( i ) - ' a ' ] ] ) { System . out . print ( str . charAt ( i ) ) ; } } } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int n = str . length ( ) ; printChar ( str , n ) ; } }
Print characters having prime frequencies in order of occurrence | Java code for the above approach ; Function to check primes ; Counting the frequency of all character using Counter function ; Traversing string ; Driver code ; Passing string to checkString function
import java . io . * ; import java . util . * ; class GFG { static boolean prime ( int n ) { if ( n <= 1 ) return false ; int max_div = ( int ) Math . floor ( Math . sqrt ( n ) ) ; for ( int i = 2 ; i < 1 + max_div ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static void checkString ( String s ) { Map < Character , Integer > freq = new HashMap < Character , Integer > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ! freq . containsKey ( s . charAt ( i ) ) ) freq . put ( s . charAt ( i ) , 0 ) ; freq . put ( s . charAt ( i ) , freq . get ( s . charAt ( i ) ) + 1 ) ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( prime ( freq . get ( s . charAt ( i ) ) ) ) System . out . print ( s . charAt ( i ) ) ; } } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; checkString ( s ) ; } }
Print characters having even frequencies in order of occurrence | Java implementation of the approach ; Function to print the even frequency characters in the order of their occurrence ; To store the frequency of each of the character of the string ; Update the frequency of each character ; Traverse str character by character ; If frequency of current character is even ; Driver code
import java . util . * ; class GFG { static int SIZE = 26 ; static void printChar ( String str , int n ) { int [ ] freq = new int [ SIZE ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ str . charAt ( i ) - ' a ' ] % 2 == 0 ) { System . out . print ( str . charAt ( i ) ) ; } } } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int n = str . length ( ) ; printChar ( str , n ) ; } }
Compare two strings considering only alphanumeric characters | Java implementation of the approach ; Function to check alphanumeric equality of both strings ; variable declaration ; Length of first string ; Length of second string ; To check each and every characters of both string ; If the current character of the first string is not an alphanumeric character , increase the pointer i ; If the current character of the second string is not an alphanumeric character , increase the pointer j ; if all alphanumeric characters of both strings are same then return true ; if any alphanumeric characters of both strings are not same then return false ; If current character matched , increase both pointers to check the next character ; If not same , then return false ; Function to print Equal or Unequal if strings are same or not ; check alphanumeric equality of both strings ; if both are alphanumeric equal , print Equal ; otherwise print Unequal ; Driver code
import java . util . * ; class GFG { static boolean CompareAlphanumeric ( char [ ] str1 , char [ ] str2 ) { int i , j ; i = 0 ; j = 0 ; int len1 = str1 . length ; int len2 = str2 . length ; while ( i <= len1 && j <= len2 ) { while ( i < len1 && ( ! ( ( str1 [ i ] >= ' a ' && str1 [ i ] <= ' z ' ) || ( str1 [ i ] >= ' A ' && str1 [ i ] <= ' Z ' ) || ( str1 [ i ] >= '0' && str1 [ i ] <= '9' ) ) ) ) { i ++ ; } while ( j < len2 && ( ! ( ( str2 [ j ] >= ' a ' && str2 [ j ] <= ' z ' ) || ( str2 [ j ] >= ' A ' && str2 [ j ] <= ' Z ' ) || ( str2 [ j ] >= '0' && str2 [ j ] <= '9' ) ) ) ) { j ++ ; } if ( i == len1 && j == len2 ) { return true ; } else if ( str1 [ i ] != str2 [ j ] ) { return false ; } else { i ++ ; j ++ ; } } return false ; } static void CompareAlphanumericUtil ( String str1 , String str2 ) { boolean res ; res = CompareAlphanumeric ( str1 . toCharArray ( ) , str2 . toCharArray ( ) ) ; if ( res == true ) { System . out . println ( " Equal " ) ; } else { System . out . println ( " Unequal " ) ; } } public static void main ( String [ ] args ) { String str1 , str2 ; str1 = " Ram , ▁ Shyam " ; str2 = " ▁ Ram ▁ - ▁ Shyam . " ; CompareAlphanumericUtil ( str1 , str2 ) ; str1 = " abc123" ; str2 = "123abc " ; CompareAlphanumericUtil ( str1 , str2 ) ; } }
Queries to print the character that occurs the maximum number of times in a given range | Java program to find the sum of the addition of all possible subsets . ; Function that answers all the queries ; Length of the string ; Number of queries ; Prefix array ; Iterate for all the characters ; Increase the count of the character ; Presum array for all 26 characters ; Update the prefix array ; Answer every query ; Range ; Iterate for all characters ; Times the lowercase character j occurs till r - th index ; Subtract the times it occurred till ( l - 1 ) th index ; Max times it occurs ; Print the answer ; Driver Code
class GFG { static void solveQueries ( String str , int [ ] [ ] query ) { int len = str . length ( ) ; int Q = query . length ; int [ ] [ ] pre = new int [ len ] [ 26 ] ; for ( int i = 0 ; i < len ; i ++ ) { pre [ i ] [ str . charAt ( i ) - ' a ' ] ++ ; if ( i > 0 ) { for ( int j = 0 ; j < 26 ; j ++ ) pre [ i ] [ j ] += pre [ i - 1 ] [ j ] ; } } for ( int i = 0 ; i < Q ; i ++ ) { int l = query [ i ] [ 0 ] ; int r = query [ i ] [ 1 ] ; int maxi = 0 ; char c = ' a ' ; for ( int j = 0 ; j < 26 ; j ++ ) { int times = pre [ r ] [ j ] ; if ( l > 0 ) times -= pre [ l - 1 ] [ j ] ; if ( times > maxi ) { maxi = times ; c = ( char ) ( ' a ' + j ) ; } } System . out . println ( " Query " + ( i + 1 ) + " : ▁ " + c ) ; } } public static void main ( String [ ] args ) { String str = " striver " ; int [ ] [ ] query = { { 0 , 1 } , { 1 , 6 } , { 5 , 6 } } ; solveQueries ( str , query ) ; } }
Check whether given string can be generated after concatenating given strings | Java implementation of the approach ; Function that return true if pre is a prefix of str ; While there are characters to match ; If characters differ at any position ; str starts with pre ; Function that return true if suff is a suffix of str ; While there are characters to match ; If characters differ at any position ; str ends with suff ; Function that returns true if str = a + b or str = b + a ; str cannot be generated by concatenating a and b ; If str starts with a i . e . a is a prefix of str ; Check if the rest of the characters are equal to b i . e . b is a suffix of str ; If str starts with b i . e . b is a prefix of str ; Check if the rest of the characters are equal to a i . e . a is a suffix of str ; Driver code
import java . util . * ; class GFG { static boolean startsWith ( String str , String pre ) { int strLen = str . length ( ) ; int preLen = pre . length ( ) ; int i = 0 , j = 0 ; while ( i < strLen && j < preLen ) { if ( str . charAt ( i ) != pre . charAt ( j ) ) return false ; i ++ ; j ++ ; } return true ; } static boolean endsWith ( String str , String suff ) { int i = str . length ( ) - 1 ; int j = suff . length ( ) - 1 ; while ( i >= 0 && j >= 0 ) { if ( str . charAt ( i ) != suff . charAt ( j ) ) return false ; i -- ; j -- ; } return true ; } static boolean checkString ( String str , String a , String b ) { if ( str . length ( ) != a . length ( ) + b . length ( ) ) return false ; if ( startsWith ( str , a ) ) { if ( endsWith ( str , b ) ) return true ; } if ( startsWith ( str , b ) ) { if ( endsWith ( str , a ) ) return true ; } return false ; } public static void main ( String args [ ] ) { String str = " GeeksforGeeks " ; String a = " Geeksfo " ; String b = " rGeeks " ; if ( checkString ( str , a , b ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Print characters having odd frequencies in order of occurrence | Java implementation of the approach ; Function to print the odd frequency characters in the order of their occurrence ; To store the frequency of each of the character of the string ; Update the frequency of each character ; Traverse str character by character ; If frequency of current character is odd ; Driver code
class GFG { public static void printChar ( String str , int n ) { int [ ] freq = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ str . charAt ( i ) - ' a ' ] % 2 == 1 ) { System . out . print ( str . charAt ( i ) ) ; } } } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int n = str . length ( ) ; printChar ( str , n ) ; } }
Minimum number of operations to move all uppercase characters before all lower case characters | Java implementation of the approach ; Function to return the minimum number of operations required ; To store the indices of the last uppercase and the first lowercase character ; Find the last uppercase character ; Find the first lowercase character ; If all the characters are either uppercase or lowercase ; Count of uppercase characters that appear after the first lowercase character ; Count of lowercase characters that appear before the last uppercase character ; Return the minimum operations required ; Driver Code
class GFG { static int minOperations ( String str , int n ) { int i , lastUpper = - 1 , firstLower = - 1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( Character . isUpperCase ( str . charAt ( i ) ) ) { lastUpper = i ; break ; } } for ( i = 0 ; i < n ; i ++ ) { if ( Character . isLowerCase ( str . charAt ( i ) ) ) { firstLower = i ; break ; } } if ( lastUpper == - 1 firstLower == - 1 ) return 0 ; int countUpper = 0 ; for ( i = firstLower ; i < n ; i ++ ) { if ( Character . isUpperCase ( str . charAt ( i ) ) ) { countUpper ++ ; } } int countLower = 0 ; for ( i = 0 ; i < lastUpper ; i ++ ) { if ( Character . isLowerCase ( str . charAt ( i ) ) ) { countLower ++ ; } } return Math . min ( countLower , countUpper ) ; } public static void main ( String args [ ] ) { String str = " geEksFOrGEekS " ; int n = str . length ( ) ; System . out . println ( minOperations ( str , n ) ) ; } }
Find the sum of all Betrothed numbers up to N | Java program to find the sum of the all betrothed numbers up to N ; Function to find the sum of the all betrothed numbers ; To store the betrothed numbers ; Calculate sum of number_1 's divisors   1 is always a divisor ; i = 2 because we don 't   want to include   1 as a divisor.  ; Sum all betrothed numbers up to N ; Driver code
import java . util . * ; class GFG { public static int Betrothed_Sum ( int n ) { Vector < Integer > Set = new Vector < Integer > ( ) ; for ( int number_1 = 1 ; number_1 < n ; number_1 ++ ) { int sum_divisor_1 = 1 ; int i = 2 ; while ( i * i <= number_1 ) { if ( number_1 % i == 0 ) { sum_divisor_1 = sum_divisor_1 + i ; if ( i * i != number_1 ) sum_divisor_1 += number_1 / i ; } i ++ ; } if ( sum_divisor_1 > number_1 ) { int number_2 = sum_divisor_1 - 1 ; int sum_divisor_2 = 1 ; int j = 2 ; while ( j * j <= number_2 ) { if ( number_2 % j == 0 ) { sum_divisor_2 += j ; if ( j * j != number_2 ) sum_divisor_2 += number_2 / j ; } j = j + 1 ; } if ( sum_divisor_2 == number_1 + 1 && number_1 <= n && number_2 <= n ) { Set . add ( number_1 ) ; Set . add ( number_2 ) ; } } } int Summ = 0 ; for ( int i = 0 ; i < Set . size ( ) ; i ++ ) { if ( Set . get ( i ) <= n ) Summ += Set . get ( i ) ; } return Summ ; } public static void main ( String [ ] args ) { int n = 78 ; System . out . println ( Betrothed_Sum ( n ) ) ; } }
Probability of rain on N + 1 th day | Java code to find the probability of rain on n + 1 - th day when previous day 's data is given ; Function to find the probability ; count 1 ; find probability ; Driver Code
import java . io . * ; import java . util . * ; class GFG { static float rainDayProbability ( int a [ ] , int n ) { float count = 0 , m ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) count ++ ; } m = count / n ; return m ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; int n = a . length ; System . out . print ( rainDayProbability ( a , n ) ) ; } }
Program to find the sum of a Series 1 + 1 / 2 ^ 2 + 1 / 3 ^ 3 + â €¦ . . + 1 / n ^ n | Java program to calculate the following series ; Function to calculate the following series ; Driver Code
import java . io . * ; class Maths { static double Series ( int n ) { int i ; double sums = 0.0 , ser ; for ( i = 1 ; i <= n ; ++ i ) { ser = 1 / Math . pow ( i , i ) ; sums += ser ; } return sums ; } public static void main ( String [ ] args ) { int n = 3 ; double res = Series ( n ) ; res = Math . round ( res * 100000.0 ) / 100000.0 ; System . out . println ( res ) ; } }