codeparrot/xlcost-text-to-code huggingface dataset:
Count pairs in an array such that the absolute difference between them is ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬¦¡¬°¥ K | Java implementation of the approach ; Function to return the count of required pairs ; Sort the given array ; To store the required count ; Update j such that it is always > i ; Find the first element arr [ j ] such that ( arr [ j ] - arr [ i ] ) >= K This is because after this element , all the elements will have absolute difference with arr [ i ] >= k and the count of valid pairs will be ( n - j ) ; Update the count of valid pairs ; Get to the next element to repeat the steps ; Return the count ; Driver code
import java . util . * ; class solution { static int count ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int cnt = 0 ; int i = 0 , j = 1 ; while ( i < n && j < n ) { j = ( j <= i ) ? ( i + 1 ) : j ; while ( j < n && ( arr [ j ] - arr [ i ] ) < k ) j ++ ; cnt += ( n - j ) ; i ++ ; } return cnt ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; int k = 2 ; System . out . println ( count ( arr , n , k ) ) ; } }
Find the volume of rectangular right wedge | Java implementation of the approach ; Function to return the volume of the rectangular right wedge ; Driver code
class GFG { static double volumeRec ( double a , double b , double e , double h ) { return ( ( ( b * h ) / 6 ) * ( 2 * a + e ) ) ; } public static void main ( String [ ] args ) throws java . lang . Exception { double a = 2 , b = 5 , e = 5 , h = 6 ; System . out . print ( " Volume ▁ = ▁ " + volumeRec ( a , b , e , h ) ) ; } }
Count squares with odd side length in Chessboard | Java implementation of the approach ; Function to return the count of odd length squares possible ; To store the required count ; For all odd values of i ; Add the count of possible squares of length i ; Return the required count ; Driver code
class GFG { static int count_square ( int n ) { int count = 0 ; for ( int i = 1 ; i <= n ; i = i + 2 ) { int k = n - i + 1 ; count += ( k * k ) ; } return count ; } public static void main ( String [ ] args ) { int N = 8 ; System . out . println ( count_square ( N ) ) ; } }
Count of elements whose absolute difference with the sum of all the other elements is greater than k | Java implementation of the approach ; Function to return the number of anomalies ; To store the count of anomalies ; To store the sum of the array elements ; Find the sum of the array elements ; Count the anomalies ; Driver code
class GFG { static int countAnomalies ( int arr [ ] , int n , int k ) { int cnt = 0 ; int i , sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) if ( Math . abs ( arr [ i ] - ( sum - arr [ i ] ) ) > k ) cnt ++ ; return cnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 } ; int n = arr . length ; int k = 1 ; System . out . print ( countAnomalies ( arr , n , k ) ) ; } }
Find the number of integers x in range ( 1 , N ) for which x and x + 1 have same number of divisors | Java implementation of the approach ; To store number of divisors and Prefix sum of such numbers ; Function to find the number of integers 1 < x < N for which x and x + 1 have the same number of positive divisors ; Count the number of divisors ; Run a loop upto sqrt ( i ) ; If j is divisor of i ; If it is perfect square ; x and x + 1 have same number of positive divisors ; Driver code ; Function call ; Required answer
class GFG { static int N = 100005 ; static int d [ ] = new int [ N ] , pre [ ] = new int [ N ] ; static void Positive_Divisors ( ) { for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { if ( j * j == i ) d [ i ] ++ ; else d [ i ] += 2 ; } } } int ans = 0 ; for ( int i = 2 ; i < N ; i ++ ) { if ( d [ i ] == d [ i - 1 ] ) ans ++ ; pre [ i ] = ans ; } } public static void main ( String [ ] args ) { Positive_Divisors ( ) ; int n = 15 ; System . out . println ( pre [ n ] ) ; } }
Length of the smallest number which is divisible by K and formed by using 1 's only | Java implementation of the approach ; Function to return length of the resultant number ; If K is a multiple of 2 or 5 ; Generate all possible numbers 1 , 11 , 111 , 111 , ... , K 1 's ; If number is divisible by k then return the length ; Driver code
class GFG { static int numLen ( int K ) { if ( K % 2 == 0 K % 5 == 0 ) { return - 1 ; } int number = 0 ; int len = 1 ; for ( len = 1 ; len <= K ; len ++ ) { number = number * 10 + 1 ; if ( ( number % K == 0 ) ) { return len ; } } return - 1 ; } public static void main ( String [ ] args ) { int K = 7 ; System . out . println ( numLen ( K ) ) ; } }
Find if the given number is present in the infinite sequence or not | Java implementation of the approach ; Function that returns true if the sequence will contain B ; Driver code
class GFG { static boolean doesContainB ( int a , int b , int c ) { if ( a == b ) { return true ; } if ( ( b - a ) * c > 0 && ( b - a ) % c == 0 ) { return true ; } return false ; } public static void main ( String [ ] args ) { int a = 1 , b = 7 , c = 3 ; if ( doesContainB ( a , b , c ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }
Find a permutation of 2 N numbers such that the result of given expression is exactly 2 K | Java program to find the required permutation of first 2 * N natural numbers ; Function to find the required permutation of first 2 * N natural numbers ; Iterate in blocks of 2 ; We need more increments , so print in reverse order ; We have enough increments , so print in same order ; Driver code
class GFG { static void printPermutation ( int n , int k ) { for ( int i = 1 ; i <= n ; i ++ ) { int x = 2 * i - 1 ; int y = 2 * i ; if ( i <= k ) System . out . print ( y + " ▁ " + x + " ▁ " ) ; else System . out . print ( x + " ▁ " + y + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 2 , k = 1 ; printPermutation ( n , k ) ; } }
Maximize the sum of products of the degrees between any two vertices of the tree | Java implementation of above approach ; Function to return the maximum possible sum ; Initialize degree for node u to 2 ; If u is the leaf node or the root node ; Initialize degree for node v to 2 ; If v is the leaf node or the root node ; Update the sum ; Driver code
class GFG { static int maxSum ( int N ) { int ans = 0 ; for ( int u = 1 ; u <= N ; u ++ ) { for ( int v = 1 ; v <= N ; v ++ ) { if ( u == v ) continue ; int degreeU = 2 ; if ( u == 1 u == N ) degreeU = 1 ; int degreeV = 2 ; if ( v == 1 v == N ) degreeV = 1 ; ans += ( degreeU * degreeV ) ; } } return ans ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . println ( maxSum ( N ) ) ; } }
Find integers that divides maximum number of elements of the array | Java implementation of the approach ; Function to print the integers that divide the maximum number of elements from the array ; Initialize two lists to store rank and factors ; Start from 2 till the maximum element in arr ; Initialize a variable to count the number of elements it is a factor of ; Maximum rank in the rank list ; Print all the elements with rank m ; Driver code
import java . util . * ; class GFG { static void maximumFactor ( int [ ] arr ) { int [ ] rank = new int [ Arrays . stream ( arr ) . max ( ) . getAsInt ( ) + 1 ] ; int [ ] factors = new int [ Arrays . stream ( arr ) . max ( ) . getAsInt ( ) + 1 ] ; int g = 0 ; for ( int i = 2 ; i <= Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < arr . length ; j ++ ) if ( arr [ j ] % i == 0 ) count += 1 ; rank [ g ] = count ; factors [ g ] = i ; g ++ ; } int m = Arrays . stream ( rank ) . max ( ) . getAsInt ( ) ; for ( int i = 0 ; i < rank . length ; i ++ ) { if ( rank [ i ] == m ) System . out . print ( factors [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 120 , 15 , 24 , 63 , 18 } ; maximumFactor ( arr ) ; } }
Natural Numbers | JAVA program to find sum of first n natural numbers . ; Returns sum of first n natural numbers ; Driver code
import java . io . * ; class GFG { static int findSum ( int n ) { int sum = 0 ; for ( int x = 1 ; x <= n ; x ++ ) sum = sum + x ; return sum ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( findSum ( n ) ) ; } }
Median | Java program to find median ; Function for calculating median ; First we sort the array ; check for even case ; Driver program
import java . util . * ; class GFG { public static double findMedian ( int a [ ] , int n ) { Arrays . sort ( a ) ; if ( n % 2 != 0 ) return ( double ) a [ n / 2 ] ; return ( double ) ( a [ ( n - 1 ) / 2 ] + a [ n / 2 ] ) / 2.0 ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 3 , 4 , 2 , 7 , 5 , 8 , 6 } ; int n = a . length ; System . out . println ( " Median ▁ = ▁ " + findMedian ( a , n ) ) ; } }
Mean | Java program to find mean ; Function for calculating mean ; Driver program
import java . util . * ; class GFG { public static double findMean ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; return ( double ) sum / ( double ) n ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 3 , 4 , 2 , 7 , 5 , 8 , 6 } ; int n = a . length ; System . out . println ( " Mean ▁ = ▁ " + findMean ( a , n ) ) ; } }
Check if the array has an element which is equal to product of remaining elements | Java implementation of the above approach ; Function to Check if the array has an element which is equal to product of all the remaining elements ; Storing frequency in map ; Calculate the product of all the elements ; If the prod is a perfect square then check if its square root ; exist in the array or not ; Driver code
import java . util . ArrayList ; class GFG { static boolean CheckArray ( int arr [ ] , int n ) { int prod = 1 ; ArrayList < Integer > freq = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { freq . add ( arr [ i ] ) ; prod *= arr [ i ] ; } int root = ( int ) Math . sqrt ( prod ) ; if ( root * root == prod ) { if ( freq . contains ( root ) & freq . lastIndexOf ( root ) != ( freq . size ( ) ) ) { return true ; } } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 12 , 3 , 2 } ; int n = arr . length ; if ( CheckArray ( arr , n ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }
Find minimum area of rectangle with given set of coordinates | package whatever Java Implementation of above approach ; # function to find minimum area of Rectangle ; creating empty columns ; fill columns with coordinates ; Driver code
import java . io . * ; import java . util . * ; class GFG { public static int minAreaRect ( int [ ] [ ] points ) { @ SuppressWarnings ( " unchecked " ) Set < Integer > columns = new HashSet ( ) ; for ( int [ ] point : points ) columns . add ( 40001 * point [ 0 ] + point [ 1 ] ) ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < points . length ; ++ i ) for ( int j = i + 1 ; j < points . length ; ++ j ) { if ( points [ i ] [ 0 ] != points [ j ] [ 0 ] && points [ i ] [ 1 ] != points [ j ] [ 1 ] ) { if ( columns . contains ( 40001 * points [ i ] [ 0 ] + points [ j ] [ 1 ] ) && columns . contains ( 40001 * points [ j ] [ 0 ] + points [ i ] [ 1 ] ) ) { ans = Math . min ( ans , Math . abs ( points [ j ] [ 0 ] - points [ i ] [ 0 ] ) * Math . abs ( points [ j ] [ 1 ] - points [ i ] [ 1 ] ) ) ; } } } return ans < Integer . MAX_VALUE ? ans : 0 ; } public static void main ( String [ ] args ) { int [ ] [ ] A = { { 1 , 1 } , { 1 , 3 } , { 3 , 1 } , { 3 , 3 } , { 2 , 2 } } ; System . out . println ( minAreaRect ( A ) ) ; } }
Check whether a number has consecutive 0 's in the given base or not | Java implementation of the above approach ; Function to convert N into base K ; Weight of each digit ; Function to check for consecutive 0 ; Flag to check if there are consecutive zero or not ; If there are two consecutive zero then returning False ; We first convert to given base , then check if the converted number has two consecutive 0 s or not ; Driver code
import java . util . * ; class GFG { static int toK ( int N , int K ) { int w = 1 ; int s = 0 ; while ( N != 0 ) { int r = N % K ; N = N / K ; s = r * w + s ; w *= 10 ; } return s ; } static boolean check ( int N ) { boolean fl = false ; while ( N != 0 ) { int r = N % 10 ; N = N / 10 ; if ( fl == true && r == 0 ) return false ; if ( r > 0 ) { fl = false ; continue ; } fl = true ; } return true ; } static void hasConsecutiveZeroes ( int N , int K ) { int z = toK ( N , K ) ; if ( check ( z ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int N = 15 ; int K = 8 ; hasConsecutiveZeroes ( N , K ) ; } }
Sum of every Kâ €™ th prime number in an array | Java implementation of the approach ; Create a boolean array " prime [ 0 . . n ] " and initialize all the entries as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; 0 and 1 are not prime numbers ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; compute the answer ; count of primes ; sum of the primes ; traverse the array ; if the number is a prime ; increase the count ; if it is the K 'th prime ; Driver code ; create the sieve
public class GFG { static int MAX = 1000000 ; static boolean prime [ ] = new boolean [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } prime [ 1 ] = false ; prime [ 0 ] = false ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= MAX ; i += p ) { prime [ i ] = false ; } } } } static void SumOfKthPrimes ( int arr [ ] , int n , int k ) { int c = 0 ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { c ++ ; if ( c % k == 0 ) { sum += arr [ i ] ; c = 0 ; } } } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int arr [ ] = { 2 , 3 , 5 , 7 , 11 } ; int n = arr . length ; int k = 2 ; SumOfKthPrimes ( arr , n , k ) ; } }
Find the super power of a given Number | Java for finding super power of n ; global hash for prime ; sieve method for storing a list of prime ; function to return super power ; find the super power ; Driver program
class GFG { static int MAX = 100000 ; static boolean [ ] prime = new boolean [ 100002 ] ; static void SieveOfEratosthenes ( ) { for ( int p = 2 ; p * p <= MAX ; p ++ ) if ( prime [ p ] == false ) for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = true ; } static int superpower ( int n ) { SieveOfEratosthenes ( ) ; int superPower = 0 , factor = 0 ; int i = 2 ; while ( n > 1 && i <= MAX ) { if ( ! prime [ i ] ) { factor = 0 ; while ( n % i == 0 && n > 1 ) { factor ++ ; n = n / i ; } if ( superPower < factor ) superPower = factor ; } i ++ ; } return superPower ; } public static void main ( String [ ] args ) { int n = 256 ; System . out . println ( superpower ( n ) ) ; } }
Count of Prime Nodes of a Singly Linked List | Java implementation to find count of prime numbers in the singly linked list ; Node of the singly linked list ; Function to insert a node at the beginning of the singly Linked List ; Function to check if a number is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to find count of prime nodes in a linked list ; If current node is prime ; Update count ; Driver program ; start with the empty list ; create the linked list 15 . 5 . 6 . 10 . 17 ; Function call to print require answer
class solution { static class Node { int data ; Node next ; } static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static int countPrime ( Node head_ref ) { int count = 0 ; Node ptr = head_ref ; while ( ptr != null ) { if ( isPrime ( ptr . data ) ) { count ++ ; } ptr = ptr . next ; } return count ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 17 ) ; head = push ( head , 10 ) ; head = push ( head , 6 ) ; head = push ( head , 5 ) ; head = push ( head , 15 ) ; System . out . print ( " Count ▁ of ▁ prime ▁ nodes ▁ = ▁ " + countPrime ( head ) ) ; } }
Smallest prime divisor of a number | Java program to count the number of subarrays that having 1 ; Function to find the smallest divisor ; if divisible by 2 ; iterate from 3 to sqrt ( n ) ; Driver Code
import java . io . * ; class GFG { static int smallestDivisor ( int n ) { if ( n % 2 == 0 ) return 2 ; for ( int i = 3 ; i * i <= n ; i += 2 ) { if ( n % i == 0 ) return i ; } return n ; } public static void main ( String [ ] args ) { int n = 31 ; System . out . println ( smallestDivisor ( n ) ) ; } }
Count Number of animals in a zoo from given number of head and legs | Java implementation of above approach ; Function that calculates Rabbits ; Driver code
import java . util . * ; import java . lang . * ; class GFG { static int countRabbits ( int Heads , int Legs ) { int count = 0 ; count = ( Legs ) - 2 * ( Heads ) ; count = count / 2 ; return count ; } public static void main ( String args [ ] ) { int Heads = 100 , Legs = 300 ; int Rabbits = countRabbits ( Heads , Legs ) ; System . out . println ( " Rabbits ▁ = ▁ " + Rabbits ) ; System . out . println ( " Pigeons ▁ = ▁ " + ( Heads - Rabbits ) ) ; } }
Program to evaluate the expression ( ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¹ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’ Ã ¢ â ‚¬¦¡¬ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¦¡ X + 1 ) ^ 6 + ( ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¹ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’ Ã ¢ â ‚¬¦¡¬ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¦¡ X | Java program to evaluate the given expression ; Function to find the sum ; Driver Code
import java . util . * ; class gfg { public static double calculateSum ( double n ) { return 2 * ( Math . pow ( n , 6 ) + 15 * Math . pow ( n , 4 ) + 15 * Math . pow ( n , 2 ) + 1 ) ; } public static void main ( String [ ] args ) { double n = 1.4142 ; System . out . println ( ( int ) Math . ceil ( calculateSum ( n ) ) ) ; } }
Find the sum of series 3 , | Java program to find sum upto N term of the series : 3 , - 6 , 12 , - 24 , ... . . ; calculate sum upto N term of series ; Driver code
import java . util . * ; class solution { static int Sum_upto_nth_Term ( int n ) { return ( 1 - ( int ) Math . pow ( - 2 , n ) ) ; } public static void main ( String arr [ ] ) { int N = 5 ; System . out . println ( Sum_upto_nth_Term ( N ) ) ; } }
Count numbers whose XOR with N is equal to OR with N | Java program to find the XOR equals OR count ; Function to calculate count of numbers with XOR equals OR ; variable to store count of unset bits ; Driver code
import java . io . * ; import java . util . * ; class GFG { static int xorEqualsOrCount ( int N ) { int count = 0 ; int bit ; while ( N > 0 ) { bit = N % 2 ; if ( bit == 0 ) count ++ ; N = N / 2 ; } return ( int ) Math . pow ( 2 , count ) ; } public static void main ( String args [ ] ) { int N = 7 ; System . out . println ( xorEqualsOrCount ( N ) ) ; } }
Program to find sum of 1 + x / 2 ! + x ^ 2 / 3 ! + ... + x ^ n / ( n + 1 ) ! | Java Program to compute sum of 1 + x / 2 ! + x ^ 2 / 3 ! + ... + x ^ n / ( n + 1 ) ! ; Method to find factorial of a number ; Method to compute the sum ; Iterate the loop till n and compute the formula ; Driver Code ; Get x and n ; Find and print the sum
public class SumOfSeries { static int fact ( int n ) { if ( n == 1 ) return 1 ; return n * fact ( n - 1 ) ; } static double sum ( int x , int n ) { double total = 1.0 ; for ( int i = 1 ; i <= n ; i ++ ) { total = total + ( Math . pow ( x , i ) / fact ( i + 1 ) ) ; } return total ; } public static void main ( String [ ] args ) { int x = 5 , n = 4 ; System . out . print ( " Sum ▁ is : ▁ " + sum ( x , n ) ) ; } }
Find Sum of Series 1 ^ 2 | Java Program to find sum of series 1 ^ 2 - 2 ^ 2 + 3 ^ 3 - 4 ^ 4 + ... ; Function to find sum of series ; If i is even ; If i is odd ; return the result ; Driver Code ; Get n ; Find the sum ; Get n ; Find the sum
import java . util . * ; import java . lang . * ; class GFG { static int sum_of_series ( int n ) { int result = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) result = result - ( int ) Math . pow ( i , 2 ) ; else result = result + ( int ) Math . pow ( i , 2 ) ; } return result ; } public static void main ( String args [ ] ) { int n = 3 ; System . out . println ( sum_of_series ( n ) ) ; n = 10 ; System . out . println ( sum_of_series ( n ) ) ; } }
Program to find the sum of the series 23 + 45 + 75 + ... . . upto N terms | Java program to find sum upto N - th term of the series : 23 , 45 , 75 , 113. . . ; return the final sum ; Driver program ; Get the value of N ; Get the sum of the series
import java . util . * ; class solution { static int findSum ( int N ) { return ( 2 * N * ( N + 1 ) * ( 4 * N + 17 ) + 54 * N ) / 6 ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( findSum ( N ) ) ; } }