"Program to find Star number | Java program to find star number ; Returns n - th star number ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int findStarNum ( int n ) { return ( 6 * n * ( n - 1 ) + 1 ) ; } public static void main ( String args [ ] ) { int n = 3 ; System . out . println ( findStarNum ( n ) ) ; } }


"Program to find Sum of a Series a ^ 1 / 1 ! + a ^ 2 / 2 ! + a ^ 3 / 3 ! + a ^ 4 / 4 ! + Ã ¢ â ‚¬¦ Ã ¢ â ‚¬¦ . + a ^ n / n ! | Java program to print the sum of series ; function to calculate sum of given series ; multiply ( a / i ) to previous term ; store result in res"
How can the above be solved in Java?

import java . io . * ; class GFG { public static void main ( String [ ] args ) { double n = 5 , a = 2 ; System . out . println ( sumOfSeries ( a , n ) ) ; } static double sumOfSeries ( double a , double n ) { double res = 0 , prev = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { prev *= ( a / i ) ; res = res + prev ; } return ( res ) ; } }


"Program to find Sum of the series 1 * 3 + 3 * 5 + ... . | Java program to find sum of first n terms ; Sn = n * ( 4 * n * n + 6 * n - 1 ) / 3 ; Driver Code ; number of terms to be included in the sum ; find the Sn"
How can the above be solved in Java?

class GFG { static int calculateSum ( int n ) { return ( n * ( 4 * n * n + 6 * n - 1 ) / 3 ) ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }


"Program to find Surface Area and Volume of Octagonal Prism | Java program to find the Surface area and volume of octagonal prism ; Function to find the Volume of octagonal prism ; Formula to calculate volume = ( area * h ) ; Display volume ; Function to find the surface area of octagonal prism ; Formula to calculate Surface area ; Driver Code"
How can the above be solved in Java?

public class GFG { static void find_volume ( double area , double h ) { double Volume = ( area * h ) ; System . out . println ( " Volume : ▁ " + Volume ) ; } static void find_Surface_area ( double area , double a , double h ) { double Surface_area = ( 2 * area ) + ( 8 * a * h ) ; System . out . println ( " Surface ▁ area : ▁ " + Surface_area ) ; } public static void main ( String [ ] args ) { double h = 1 ; double a = 6 ; double d = 2 ; double area = 2 * a * d ; find_Surface_area ( area , a , h ) ; find_volume ( area , h ) ; } }


"Program to find X , Y and Z intercepts of a plane | Java program to find the X , Y and Z intercepts of a plane ; For finding the x - intercept put y = 0 and z = 0 ; For finding the y - intercept put x = 0 and z = 0 ; For finding the z - intercept put x = 0 and y = 0 ; For Finding value of A , B , C , D ; Calling the first created function ; Driver Code"
How can the above be solved in Java?

import java . util . * ; class solution { static double [ ] XandYandZintercept ( double A , double B , double C , double D ) { double [ ] rslt = new double [ 3 ] ; double x = - D / A ; double y = - D / B ; double z = - D / C ; rslt [ 0 ] = x ; rslt [ 1 ] = y ; rslt [ 2 ] = z ; return rslt ; } static void equation_plane ( int [ ] p , int [ ] q , int [ ] r ) { int x1 = p [ 0 ] ; int y1 = p [ 1 ] ; int z1 = p [ 2 ] ; int x2 = q [ 0 ] ; int y2 = q [ 1 ] ; int z2 = q [ 2 ] ; int x3 = r [ 0 ] ; int y3 = r [ 1 ] ; int z3 = r [ 2 ] ; int a1 = x2 - x1 ; int b1 = y2 - y1 ; int c1 = z2 - z1 ; int a2 = x3 - x1 ; int b2 = y3 - y1 ; int c2 = z3 - z1 ; int A = b1 * c2 - b2 * c1 ; int B = a2 * c1 - a1 * c2 ; int C = a1 * b2 - b1 * a2 ; int D = ( - A * x1 - B * y1 - C * z1 ) ; double [ ] rslt = XandYandZintercept ( A , B , C , D ) ; for ( int i = 0 ; i < 3 ; i ++ ) { System . out . printf ( rslt [ i ] + " ▁ " ) ; } } public static void main ( String args [ ] ) { int x1 = - 1 ; int y1 = 2 ; int z1 = 1 ; int x2 = 0 ; int y2 = - 3 ; int z2 = 2 ; int x3 = 1 ; int y3 = 1 ; int z3 = - 4 ; int [ ] p = { x1 , y1 , z1 } ; int [ ] q = { x2 , y2 , z2 } ; int [ ] r = { x3 , y3 , z3 } ; equation_plane ( p , q , r ) ; } }


"Program to find all Factors of a Number using recursion | Java program to find all the factors of a number using recursion ; Recursive function to print factors of a number ; Checking if the number is less than N ; Calling the function recursively for the next number ; Driver code"
How can the above be solved in Java?

class GFG { static void factors ( int n , int i ) { if ( i <= n ) { if ( n % i == 0 ) { System . out . print ( i + " ▁ " ) ; } factors ( n , i + 1 ) ; } } public static void main ( String args [ ] ) { int N = 16 ; factors ( N , 1 ) ; } }


"Program to find amount of water in a given glass | Program to find the amount / of water in j - th glass of i - th row ; Returns the amount of water in jth glass of ith row ; A row number i has maximum i columns . So input column number must be less than i ; There will be i * ( i + 1 ) / 2 glasses till ith row ( including ith row ) ; Put all water in first glass ; Now let the water flow to the downward glasses till the row number is less than or / equal to i ( given row ) correction : X can be zero for side glasses as they have lower rate to fill ; Fill glasses in a given row . Number of columns in a row is equal to row number ; Get the water from current glass ; Keep the amount less than or equal to capacity in current glass ; Get the remaining amount ; Distribute the remaining amount to the down two glasses ; The index of jth glass in ith row will be i * ( i - 1 ) / 2 + j - 1 ; Driver Code ; Total amount of water"
How can the above be solved in Java?

import java . lang . * ; class GFG { static float findWater ( int i , int j , float X ) { if ( j > i ) { System . out . println ( " Incorrect ▁ Input " ) ; System . exit ( 0 ) ; } int ll = Math . round ( ( i * ( i + 1 ) ) ) ; float [ ] glass = new float [ ll + 2 ] ; int index = 0 ; glass [ index ] = X ; for ( int row = 1 ; row <= i ; ++ row ) { for ( int col = 1 ; col <= row ; ++ col , ++ index ) { X = glass [ index ] ; glass [ index ] = ( X >= 1.0f ) ? 1.0f : X ; X = ( X >= 1.0f ) ? ( X - 1 ) : 0.0f ; glass [ index + row ] += X / 2 ; glass [ index + row + 1 ] += X / 2 ; } } return glass [ ( int ) ( i * ( i - 1 ) / 2 + j - 1 ) ] ; } public static void main ( String [ ] args ) { int i = 2 , j = 2 ; float X = 2.0f ; System . out . println ( " Amount ▁ of ▁ water ▁ in ▁ jth ▁ " + " glass ▁ of ▁ ith ▁ row ▁ is : ▁ " + findWater ( i , j , X ) ) ; } }


"Program to find amount of water in a given glass | Program to find the amount / of water in j - th glass of i - th row ; class Triplet which stores curr row curr col and curr rem - water of every glass ; Returns the amount of water in jth glass of ith row ; stores how much amount of water present in every glass ; store Triplet i . e curr - row , curr - col , rem - water ; we take the center of the first row for the location of the first glass ; this while loop runs unless the queue is not empty ; First we remove the Triplet from the queue ; as we know we have to calculate the amount of water in jth glass of ith row . so first we check if we find solutions for the the every glass of i 'th row.  so, if we have calculated the result  then we break the loop  and return our answer ; As we know maximum capacity of every glass is 1 unit . so first we check the capacity of curr glass is full or not . ; calculate the remaining capacity of water for curr glass ; if the remaining capacity of water for curr glass is greater than then the remaining capacity of tatal water then we put all remaining water into curr glass ; if remaining capacity of tatal water is not equal to zero then we add left and right glass of the next row and gives half capacity of tatal water to both the glass ; return the result for jth glass of ith row ; Driver Code ; Total amount of water"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class Triplet { int row ; int col ; double rem_water ; Triplet ( int row , int col , double rem_water ) { this . row = row ; this . col = col ; this . rem_water = rem_water ; } } class GFG { public static double findWater ( int i , int j , int totalWater ) { double dp [ ] [ ] = new double [ i + 1 ] [ 2 * i + 1 ] ; Queue < Triplet > queue = new LinkedList < > ( ) ; queue . add ( new Triplet ( 0 , i , totalWater ) ) ; while ( ! queue . isEmpty ( ) ) { Triplet curr = queue . remove ( ) ; if ( curr . row == i ) break ; if ( dp [ curr . row ] [ curr . col ] != 1.0 ) { double rem_water = 1 - dp [ curr . row ] [ curr . col ] ; if ( rem_water > curr . rem_water ) { dp [ curr . row ] [ curr . col ] += curr . rem_water ; curr . rem_water = 0 ; } else { dp [ curr . row ] [ curr . col ] += rem_water ; curr . rem_water -= rem_water ; } } if ( curr . rem_water != 0 ) { queue . add ( new Triplet ( curr . row + 1 , curr . col - 1 , curr . rem_water / 2.0 ) ) ; queue . add ( new Triplet ( curr . row + 1 , curr . col + 1 , curr . rem_water / 2.0 ) ) ; } } return dp [ i - 1 ] [ 2 * j - 1 ] ; } public static void main ( String [ ] args ) { int i = 2 , j = 2 ; int totalWater = 2 ; System . out . print ( " Amount ▁ of ▁ water ▁ in ▁ jth ▁ glass ▁ of ▁ ith ▁ row ▁ is : " ) ; System . out . format ( " % .6f " , findWater ( i , j , totalWater ) ) ; } }


"Program to find correlation coefficient | JAVA Program to find correlation coefficient ; function that returns correlation coefficient . ; sum of elements of array X . ; sum of elements of array Y . ; sum of X [ i ] * Y [ i ] . ; sum of square of array elements . ; use formula for calculating correlation coefficient . ; Driver function ; Find the size of array . ; Function call to correlationCoefficient ."
How can the above be solved in Java?

import java . math . * ; class GFG { static float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) { int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ; int squareSum_X = 0 , squareSum_Y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum_X = sum_X + X [ i ] ; sum_Y = sum_Y + Y [ i ] ; sum_XY = sum_XY + X [ i ] * Y [ i ] ; squareSum_X = squareSum_X + X [ i ] * X [ i ] ; squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ; } float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ; return corr ; } public static void main ( String args [ ] ) { int X [ ] = { 15 , 18 , 21 , 24 , 27 } ; int Y [ ] = { 25 , 25 , 27 , 31 , 32 } ; int n = X . length ; System . out . printf ( " % 6f " , correlationCoefficient ( X , Y , n ) ) ; } }


"Program to find count of numbers having odd number of divisors in given range | Java implementation of the approach ; Function to return the count of divisors of a number ; Count the powers of the current prime i which divides a ; Update the count of divisors ; Reset the count ; If the remaining a is prime then a ^ 1 will be one of its prime factors ; Function to count numbers having odd number of divisors in range [ A , B ] ; To store the count of elements having odd number of divisors ; Iterate from a to b and find the count of their divisors ; To store the count of divisors of i ; If the divisor count of i is odd ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static int divisor ( int a ) { int div = 1 , count = 0 ; for ( int i = 2 ; i <= Math . sqrt ( a ) ; i ++ ) { while ( a % i == 0 ) { count ++ ; a = a / i ; } div = div * ( count + 1 ) ; count = 0 ; } if ( a > 1 ) { div = div * ( 2 ) ; } return div ; } static int OddDivCount ( int a , int b ) { int res = 0 ; for ( int i = a ; i <= b ; ++ i ) { int divCount = divisor ( i ) ; if ( divCount % 2 == 1 ) { ++ res ; } } return res ; } public static void main ( String [ ] args ) { int a = 1 , b = 10 ; System . out . println ( OddDivCount ( a , b ) ) ; } }


"Program to find count of numbers having odd number of divisors in given range | Java program to find count of numbers having odd number of divisors in given range ; Function to count numbers having odd number of divisors in range [ A , B ] ; variable to odd divisor count ; iterate from a to b and count their number of divisors ; variable to divisor count ; if count of divisor is odd then increase res by 1 ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int OddDivCount ( int a , int b ) { int res = 0 ; for ( int i = a ; i <= b ; ++ i ) { int divCount = 0 ; for ( int j = 1 ; j <= i ; ++ j ) { if ( i % j == 0 ) { ++ divCount ; } } if ( ( divCount % 2 ) != 0 ) { ++ res ; } } return res ; } public static void main ( String [ ] args ) { int a = 1 , b = 10 ; System . out . println ( OddDivCount ( a , b ) ) ; } }


"Program to find equation of a plane passing through 3 points | Java program to find equation of a plane passing through given 3 points . ; Function to find equation of plane . ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static void equation_plane ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , float x3 , float y3 , float z3 ) { float a1 = x2 - x1 ; float b1 = y2 - y1 ; float c1 = z2 - z1 ; float a2 = x3 - x1 ; float b2 = y3 - y1 ; float c2 = z3 - z1 ; float a = b1 * c2 - b2 * c1 ; float b = a2 * c1 - a1 * c2 ; float c = a1 * b2 - b1 * a2 ; float d = ( - a * x1 - b * y1 - c * z1 ) ; System . out . println ( " equation ▁ of ▁ plane ▁ is ▁ " + a + " ▁ x ▁ + ▁ " + b + " ▁ y ▁ + ▁ " + c + " ▁ z ▁ + ▁ " + d + " ▁ = ▁ 0 . " ) ; } public static void main ( String [ ] args ) { float x1 = - 1 ; float y1 = 2 ; float z1 = 1 ; float x2 = 0 ; float y2 = - 3 ; float z2 = 2 ; float x3 = 1 ; float y3 = 1 ; float z3 = - 4 ; equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ; } }


"Program to find first N Iccanobif Numbers | Java program to find first N Icanobif numbers ; Iterative function to reverse digits of num ; Function to print first N Icanobif Numbers ; Initialize first , second numbers ; Print first two numbers ; Reversing digit of previous two terms and adding them ; Driver Code"
How can the above be solved in Java?

public class GFG { static int reversDigits ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } static void icanobifNumbers ( int N ) { int first = 0 , second = 1 ; if ( N == 1 ) System . out . print ( first ) ; else if ( N == 2 ) System . out . print ( first + " ▁ " + second ) ; else { System . out . print ( first + " ▁ " + second + " ▁ " ) ; for ( int i = 3 ; i <= N ; i ++ ) { int x = reversDigits ( first ) ; int y = reversDigits ( second ) ; System . out . print ( x + y + " ▁ " ) ; int temp = second ; second = x + y ; first = temp ; } } } public static void main ( String [ ] args ) { int N = 12 ; icanobifNumbers ( N ) ; } }


"Program to find greater value between a ^ n and b ^ n | JAVA code for finding greater between the a ^ n and b ^ n ; Function to find the greater value ; If n is even ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static void findGreater ( int a , int b , int n ) { if ( ! ( ( n & 1 ) > 0 ) ) { a = Math . abs ( a ) ; b = Math . abs ( b ) ; } if ( a == b ) System . out . println ( " a ^ n ▁ is ▁ " + " equal ▁ to ▁ b ^ n " ) ; else if ( a > b ) System . out . println ( " a ^ n ▁ is ▁ greater ▁ " + " than ▁ b ^ n " ) ; else System . out . println ( " b ^ n ▁ is ▁ greater ▁ " + " than ▁ a ^ n " ) ; } public static void main ( String [ ] args ) { int a = 12 , b = 24 , n = 5 ; findGreater ( a , b , n ) ; } }


"Program to find if two numbers and their AM and HM are present in an array using STL | Java program to check if two numbers are present in an array then their AM and HM are also present . Finally , find the GM of the numbers ; Function to find the Arithmetic Mean of 2 numbers ; Function to find the Harmonic Mean of 2 numbers ; Following function checks and computes the desired results based on the means ; Calculate means ; Hash container ( HashMap ) to store elements ; Insertion of array elements in the Set ; Conditionals to check if numbers are present in array by Hashing ; Conditionals to check if the AM and HM of the numbers are present in array ; If all conditions are satisfied , the Geometric Mean is calculated ; If numbers are found but the respective AM and HM are not found in the array ; If none of the conditions are satisfied ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static Double ArithmeticMean ( Double A , Double B ) { return ( A + B ) / 2 ; } static Double HarmonicMean ( Double A , Double B ) { return ( 2 * A * B ) / ( A + B ) ; } static void CheckArithmeticHarmonic ( Double arr [ ] , Double A , Double B , int N ) { Double AM = ArithmeticMean ( A , B ) ; Double HM = HarmonicMean ( A , B ) ; HashMap < Double , Integer > Hash = new HashMap < Double , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Hash . put ( arr [ i ] , 1 ) ; } if ( Hash . get ( A ) != 0 && Hash . get ( B ) != 0 ) { if ( Hash . get ( AM ) != 0 && Hash . get ( HM ) != 0 ) { System . out . print ( " GM ▁ = ▁ " ) ; System . out . format ( " % .2f " , Math . sqrt ( AM * HM ) ) ; } else { System . out . print ( " AM ▁ and ▁ HM ▁ not ▁ found " ) ; } } else { System . out . print ( " numbers ▁ not ▁ found " ) ; } } public static void main ( String args [ ] ) { Double arr [ ] = { 1.0 , 2.0 , 2.5 , 3.0 , 4.0 , 4.5 , 5.0 , 6.0 } ; int N = ( arr . length ) ; Double A = 3.0 ; Double B = 6.0 ; CheckArithmeticHarmonic ( arr , A , B , N ) ; } }


"Program to find largest element in an array | Java Program to find maximum in arr [ ] ; Method to find maximum in arr [ ] ; Initialize maximum element ; Traverse array elements from second and compare every element with current max ; Driver method"
How can the above be solved in Java?

class Test { static int arr [ ] = { 10 , 324 , 45 , 90 , 9808 } ; static int largest ( ) { int i ; int max = arr [ 0 ] ; for ( i = 1 ; i < arr . length ; i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ; return max ; } public static void main ( String [ ] args ) { System . out . println ( " Largest ▁ in ▁ given ▁ array ▁ is ▁ " + largest ( ) ) ; } }


"Program to find largest element in an array | Java program to find maximum in arr [ ] of size n ; returns maximum in arr [ ] of size n ; Driver code"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { static int largest ( int [ ] arr , int n ) { Arrays . sort ( arr ) ; return arr [ n - 1 ] ; } static public void main ( String [ ] args ) { int [ ] arr = { 10 , 324 , 45 , 90 , 9808 } ; int n = arr . length ; System . out . println ( largest ( arr , n ) ) ; } }


"Program to find last two digits of 2 ^ n | Java code to find last 2 digits of 2 ^ n ; Find the first digit ; Get the last digit from the number ; Remove last digit from number ; Get the last digit from the number ( last second of num ) ; Take last digit to ten 's position  i.e. last second digit ; Add the value of ones and tens to make it complete 2 digit number ; return the first digit ; Driver code ; pow function used"
How can the above be solved in Java?

class Geeks { static long LastTwoDigit ( long num ) { long one = num % 10 ; num /= 10 ; long tens = num % 10 ; tens *= 10 ; num = tens + one ; return num ; } public static void main ( String args [ ] ) { int n = 10 ; long num = 1 ; num = ( long ) Math . pow ( 2 , n ) ; System . out . println ( " Last ▁ 2 ▁ digits ▁ of ▁ 2 ^ 10 ▁ = ▁ " + LastTwoDigit ( num ) ) ; } }


"Program to find last two digits of 2 ^ n | Java code to find last 2 digits of 2 ^ n ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; x = x % p ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Java function to calculate number of digits in x ; Java function to print last 2 digits of 2 ^ n ; Generating 10 ^ 2 ; Calling modular exponentiation ; Printing leftmost zeros . Since ( 2 ^ n ) % 2 can have digits less then 2. In that case we need to print zeros ; If temp is not zero then print temp . If temp is zero then already printed ; Driver Code"
How can the above be solved in Java?

class GFG { static int power ( long x , long y , long p ) { while ( y > 0 ) { long r = y & 1 ; if ( r == 1 ) res = ( res * ( int ) x ) % ( int ) p ; x = ( x * x ) % p ; } return res ; } static int numberOfDigits ( int x ) { int i = 0 ; while ( x != 0 ) { x /= 10 ; i ++ ; } return i ; } static void LastTwoDigit ( int n ) { System . out . print ( " Last ▁ " + 2 + " ▁ digits ▁ of ▁ " + 2 + " ^ " ) ; System . out . print ( n + " ▁ = ▁ " ) ; int temp = 1 ; for ( int i = 1 ; i <= 2 ; i ++ ) temp *= 10 ; temp = power ( 2 , n , temp ) ; for ( int i = 0 ; i < ( 2 - numberOfDigits ( temp ) ) ; i ++ ) System . out . print ( 0 + " ▁ " ) ; if ( temp != 0 ) System . out . println ( temp ) ; } public static void main ( String [ ] args ) { int n = 72 ; LastTwoDigit ( n ) ; } }


"Program to find line passing through 2 Points | Java Implementation to find the line passing through two points ; This pair is used to store the X and Y coordinate of a point respectively ; Function to find the line given two points ; Driver code"
How can the above be solved in Java?

class GFG { static class Pair { int first , second ; public Pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void lineFromPoints ( Pair P , Pair Q ) { int a = Q . second - P . second ; int b = P . first - Q . first ; int c = a * ( P . first ) + b * ( P . second ) ; if ( b < 0 ) { System . out . println ( " The ▁ line ▁ passing ▁ through ▁ points ▁ P ▁ and ▁ Q ▁ is : ▁ " + a + " x ▁ - ▁ " + b + " y ▁ = ▁ " + c ) ; } else { System . out . println ( " The ▁ line ▁ passing ▁ through ▁ points ▁ P ▁ and ▁ Q ▁ is : ▁ " + a + " x ▁ + ▁ " + b + " y ▁ = ▁ " + c ) ; } } public static void main ( String [ ] args ) { Pair P = new Pair ( 3 , 2 ) ; Pair Q = new Pair ( 2 , 6 ) ; lineFromPoints ( P , Q ) ; } }


"Program to find minimum number of lectures to attend to maintain 75 % | Java Program to find minimum number of lectures to attend to maintain 75 % attendance ; Method to compute minimum lecture ; Formula to compute ; Driver Code"
How can the above be solved in Java?

public class GFG { static int minimumLectures ( int m , int n ) { int ans = 0 ; if ( n < ( int ) Math . ceil ( 0.75 * m ) ) ans = ( int ) Math . ceil ( ( ( 0.75 * m ) - n ) / 0.25 ) ; else ans = 0 ; return ans ; } public static void main ( String [ ] args ) { int M = 9 , N = 1 ; System . out . println ( minimumLectures ( M , N ) ) ; } }


"Program to find nth term of the series 1 4 15 24 45 60 92 | Java implementation of the above approach ; function to calculate nth term of the series ; variable nth will store the nth term of series ; if n is even ; if n is odd ; return nth term ; Driver code"
How can the above be solved in Java?

class GFG { static long nthTerm ( long n ) { long nth ; if ( n % 2 == 0 ) nth = 2 * ( ( n * n ) - n ) ; else nth = ( 2 * n * n ) - n ; return nth ; } public static void main ( String [ ] args ) { long n ; n = 5 ; System . out . println ( nthTerm ( n ) ) ; n = 25 ; System . out . println ( nthTerm ( n ) ) ; n = 25000000 ; System . out . println ( nthTerm ( n ) ) ; n = 250000007 ; System . out . println ( nthTerm ( n ) ) ; } }


"Program to find number of solutions in Quadratic Equation | Java Program to find the solutions of specified equations ; Method to check for solutions of equations ; If the expression is greater than 0 , then 2 solutions ; If the expression is equal 0 , then 2 solutions ; Else no solutions ; Driver Code"
How can the above be solved in Java?

public class GFG { static void checkSolution ( int a , int b , int c ) { if ( ( ( b * b ) - ( 4 * a * c ) ) > 0 ) System . out . println ( "2 ▁ solutions " ) ; else if ( ( ( b * b ) - ( 4 * a * c ) ) == 0 ) System . out . println ( "1 ▁ solution " ) ; else System . out . println ( " No ▁ solutions " ) ; } public static void main ( String [ ] args ) { int a = 2 , b = 5 , c = 2 ; checkSolution ( a , b , c ) ; } }


"Program to find remainder when large number is divided by 11 | JAVA implementation to find remainder when a large number is divided by 11 ; Function to return remainder ; len is variable to store the length of number string . ; loop that find remainder ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int remainder ( String str ) { int len = str . length ( ) ; int num , rem = 0 ; for ( int i = 0 ; i < len ; i ++ ) { num = rem * 10 + ( str . charAt ( i ) - '0' ) ; rem = num % 11 ; } return rem ; } public static void main ( String args [ ] ) { String str = "3435346456547566345436457867978" ; System . out . println ( remainder ( str ) ) ; } }


"Program to find remainder when large number is divided by r | Java implementation to find Remainder when a large Number is divided by R ; Function to Return Remainder ; len is variable to store the length of Number string . ; loop that find Remainder ; Return the remainder ; Driver code ; Get the large number as string ; Get the divisor R ; Find and print the remainder"
How can the above be solved in Java?

class GFG { static int Remainder ( String str , int R ) { int len = str . length ( ) ; int Num , Rem = 0 ; for ( int i = 0 ; i < len ; i ++ ) { Num = Rem * 10 + ( str . charAt ( i ) - '0' ) ; Rem = Num % R ; } return Rem ; } public static void main ( String [ ] args ) { String str = "13589234356546756" ; int R = 13 ; System . out . println ( Remainder ( str , R ) ) ; } }


"Program to find remainder without using modulo or % operator | A Java implementation of the approach ; Function to return num % divisor without using % ( modulo ) operator ; While divisor is smaller than n , keep subtracting it from num ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static int getRemainder ( int num , int divisor ) { while ( num >= divisor ) num -= divisor ; return num ; } public static void main ( String [ ] args ) { int num = 100 , divisor = 7 ; System . out . println ( getRemainder ( num , divisor ) ) ; } }


"Program to find remainder without using modulo or % operator | Java program to find remainder without using modulo operator ; This function returns remainder of num / divisor without using % ( modulo ) operator ; Driver program to test above functions"
How can the above be solved in Java?

import java . io . * ; class GFG { static int getRemainder ( int num , int divisor ) { return ( num - divisor * ( num / divisor ) ) ; } public static void main ( String [ ] args ) { System . out . println ( getRemainder ( 100 , 7 ) ) ; } }


"Program to find simple interest | A Simple JAVA program to compute simple interest for given principal amount , time and rate of interest . ; We can change values here for different inputs ; Calculate simple interest ; Print the resultant value of SI"
How can the above be solved in Java?

import java . io . * ; class GFG { public static void main ( String args [ ] ) { float P = 1 , R = 1 , T = 1 ; float SI = ( P * T * R ) / 100 ; System . out . println ( " Simple ▁ interest ▁ = ▁ " + SI ) ; } }


"Program to find simple moving average | Java program to calculate Simple Moving Average ; queue used to store list so that we get the average ; constructor to initialize period ; function to add new data in the list and update the sum so that we get the new mean ; Updating size so that length of data set should be equal to period as a normal mean has ; function to calculate mean ; Driver code"
How can the above be solved in Java?

import java . util . * ; public class SimpleMovingAverage { private final Queue < Double > Dataset = new LinkedList < Double > ( ) ; private final int period ; private double sum ; public SimpleMovingAverage ( int period ) { this . period = period ; } public void addData ( double num ) { sum += num ; Dataset . add ( num ) ; if ( Dataset . size ( ) > period ) { sum -= Dataset . remove ( ) ; } } public double getMean ( ) { return sum / period ; } public static void main ( String [ ] args ) { double [ ] input_data = { 1 , 3 , 5 , 6 , 8 , 12 , 18 , 21 , 22 , 25 } ; int per = 3 ; SimpleMovingAverage obj = new SimpleMovingAverage ( per ) ; for ( double x : input_data ) { obj . addData ( x ) ; System . out . println ( " New ▁ number ▁ added ▁ is ▁ " + x + " , ▁ SMA ▁ = ▁ " + obj . getMean ( ) ) ; } } }


"Program to find slant height of cone and pyramid | Java program for the above approach ; Function to calculate slant height of a cone ; Store the slant height of cone ; Print the result ; Function to find the slant height of a pyramid ; Store the slant height of pyramid ; Print the result ; Driver Code ; Dimensions of Cone ; Function Call for slant height of Cone ; Dimensions of Pyramid ; Function to calculate slant height of a pyramid"
How can the above be solved in Java?

import java . io . * ; class GFG { static void coneSlantHeight ( double cone_h , double cone_r ) { double slant_height_cone = Math . sqrt ( Math . pow ( cone_h , 2 ) + Math . pow ( cone_r , 2 ) ) ; System . out . println ( " Slant ▁ height ▁ of ▁ cone ▁ is : ▁ " + slant_height_cone ) ; } static void pyramidSlantHeight ( double pyramid_h , double pyramid_s ) { double slant_height_pyramid = Math . sqrt ( Math . pow ( pyramid_s / 2 , 2 ) + Math . pow ( pyramid_h , 2 ) ) ; System . out . println ( " Slant ▁ height ▁ of ▁ pyramid ▁ is : ▁ " + slant_height_pyramid ) ; } public static void main ( String [ ] args ) { double H1 = 4.5 , R = 6 ; coneSlantHeight ( H1 , R ) ; double H2 = 4 , S = 4.8 ; pyramidSlantHeight ( H2 , S ) ; } }


"Program to find slope of a line | Java program for slope of line ; function to find the slope of a straight line ; driver code to check the above function"
How can the above be solved in Java?

import java . util . * ; class GFG { static float slope ( float x1 , float y1 , float x2 , float y2 ) { if ( x1 == x2 ) return Integer . MAX_VALUE ; return ( y2 - y1 ) / ( x2 - x1 ) ; } public static void main ( String [ ] args ) { float x1 = 4 , y1 = 2 ; float x2 = 2 , y2 = 5 ; System . out . print ( " Slope ▁ is : ▁ " + slope ( x1 , y1 , x2 , y2 ) ) ; } }


"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"
How can the above be solved in Java?

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 ) ) ; } }


"Program to find sum of 1 + x / 2 ! + x ^ 2 / 3 ! + ... + x ^ n / ( n + 1 ) ! | Java implementation of the approach ; Function to compute the series sum ; To store the value of S [ i - 1 ] ; Iterate over n to store sum in total ; Update previous with S [ i ] ; Driver code ; Get x and n ; Find and print the sum"
How can the above be solved in Java?

public class GFG { static double sum ( int x , int n ) { double total = 1.0 ; double previous = 1.0 ; for ( int i = 1 ; i <= n ; i ++ ) { previous = ( previous * x ) / ( i + 1 ) ; total = total + previous ; } return total ; } public static void main ( String [ ] args ) { int x = 5 , n = 4 ; System . out . print ( " Sum ▁ is : ▁ " + sum ( x , n ) ) ; } }


"Program to find sum of first n natural numbers | Efficient JAVA program to find sum of first n natural numbers . ; Returns sum of first n natural numbers ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int findSum ( int n ) { return n * ( n + 1 ) / 2 ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( findSum ( n ) ) ; } }


"Program to find sum of first n natural numbers | Efficient JAVA program to find sum of first n natural numbers that avoids overflow if result is going to be within limits . ; Returns sum of first n natural numbers ; If n is odd , ( n + 1 ) must be even ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int findSum ( int n ) { if ( n % 2 == 0 ) return ( n / 2 ) * ( n + 1 ) ; else return ( ( n + 1 ) / 2 ) * n ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( findSum ( n ) ) ; } }


"Program to find sum of first n natural numbers | JAVA program to find sum of first n natural numbers . ; Returns sum of first n natural numbers ; Driver code"
How can the above be solved in Java?

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 ) ) ; } }


"Program to find sum of harmonic series | Java Program to find sum of harmonic series ; Function to return sum of harmonic series ; Driven Program"
How can the above be solved in Java?

import java . io . * ; class GFG { static double sum ( int n ) { double i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return s ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . printf ( " Sum ▁ is ▁ % f " , sum ( n ) ) ; } }


"Program to find sum of harmonic series | Java program to find sum of harmonic series using recursion ; Base condition ; Driven Code"
How can the above be solved in Java?

import java . io . * ; class GFG { float sum ( float n ) { if ( n < 2 ) return 1 ; else return 1 / n + ( sum ( n - 1 ) ) ; } public static void main ( String args [ ] ) { GFG g = new GFG ( ) ; System . out . println ( g . sum ( 8 ) ) ; System . out . print ( g . sum ( 10 ) ) ; } }


"Program to find sum of series 1 * 2 * 3 + 2 * 3 * 4 + 3 * 4 * 5 + . . . + n * ( n + 1 ) * ( n + 2 ) | Java Program to find the sum of series 1 * 2 * 3 + 2 * 3 * 4 + . . . + n * ( n + 1 ) * ( n + 1 ) ; Function to calculate sum of series . ; Driver Code"
How can the above be solved in Java?

public class GfG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum = sum + i * ( i + 1 ) * ( i + 2 ) ; return sum ; } public static void main ( String s [ ] ) { int n = 10 ; System . out . println ( sumOfSeries ( n ) ) ; } }


"Program to find sum of series 1 + 1 / 2 + 1 / 3 + 1 / 4 + . . + 1 / n | Java Program to find sum of series ; Function to return sum of 1 / 1 + 1 / 2 + 1 / 3 + . . + 1 / n ; Driven Program"
How can the above be solved in Java?


"Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | Java Program to find sum of series 1 + 2 + 2 + 3 + . . . + n ; Function that find sum of series . ; Driver Code ; Function call"
How can the above be solved in Java?

public class GfG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= i ; j ++ ) sum = sum + i ; return sum ; } public static void main ( String s [ ] ) { int n = 10 ; System . out . println ( sumOfSeries ( n ) ) ; } }


public class GfG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum = sum + i * i ; return sum ; } public static void main ( String args [ ] ) { int n = 10 ; System . out . println ( sumOfSeries ( n ) ) ; } }


"Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | Java Program to find sum of series 1 + 2 + 2 + 3 + . . . + n ; Function that find sum of series . ; Driver Code"
How can the above be solved in Java?

public class GfG { static int sumOfSeries ( int n ) { return ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; } public static void main ( String s [ ] ) { int n = 10 ; System . out . println ( sumOfSeries ( n ) ) ; } }


"Program to find sum of the given sequence | Java program to find the sum of the given sequence ; function to find moudulo inverse under 10 ^ 9 + 7 ; Function to find the sum of the given sequence ; Driver code"
How can the above be solved in Java?

class GFG { static long MOD = 1000000007 ; static long modInv ( long x ) { long n = MOD - 2 ; long result = 1 ; while ( n > 0 ) { if ( ( n & 1 ) > 0 ) { result = result * x % MOD ; } x = x * x % MOD ; n = n / 2 ; } return result ; } static long getSum ( long n , long k ) { long ans = 1 ; for ( long i = n + 1 ; i > n - k ; i -- ) { ans = ans * i % MOD ; } ans = ans * modInv ( k + 1 ) % MOD ; return ans ; } public static void main ( String [ ] args ) { long n = 3 , k = 2 ; System . out . println ( getSum ( n , k ) ) ; } }


"Program to find the Area and Perimeter of a Semicircle | Java program to find the Area and Perimeter of a Semicircle ; Function for calculating the area ; Formula for finding the area ; Function for calculating the perimeter ; Formula for finding the perimeter ; driver code ; Get the radius ; Find the area ; Find the perimeter"
How can the above be solved in Java?

import java . io . * ; class GFG { static float area ( float r ) { return ( float ) ( ( 0.5 ) * ( 3.14 ) * ( r * r ) ) ; } static float perimeter ( float r ) { return ( float ) ( ( 3.14 ) * ( r ) ) ; } public static void main ( String [ ] args ) { float r = 10 ; System . out . println ( " The ▁ Area ▁ of ▁ Semicircle : ▁ " + area ( r ) ) ; System . out . println ( " The ▁ Perimeter ▁ of ▁ Semicircle : " + + perimeter ( r ) ) ; } }


"Program to find the Area and Volume of Icosahedron | Java program to find the Area and volume of Icosahedron ; Function to find area of Icosahedron ; Formula to calculating area ; Function to find volume of Icosahedron ; Formula to calculating volume ; Driver code ; Function call to find area of Icosahedron . ; Function call to find volume of Icosahedron ."
How can the above be solved in Java?

import java . io . * ; class GFG { static float findArea ( float a ) { float area ; area = ( float ) ( 5 * Math . sqrt ( 3 ) * a * a ) ; return area ; } static float findVolume ( float a ) { float volume ; volume = ( float ) ( ( ( float ) 5 / 12 ) * ( 3 + Math . sqrt ( 5 ) ) * a * a * a ) ; return volume ; } public static void main ( String [ ] args ) { float a = 5 ; System . out . println ( " Area : ▁ " + findArea ( a ) ) ; System . out . println ( " Volume : ▁ " + findVolume ( a ) ) ; } }


"Program to find the Area of an Ellipse | Java program to find area of an Ellipse . ; Function to find area of an ellipse . ; formula to find the area of an Ellipse . ; Display the result ; Driver code"
How can the above be solved in Java?

class GFG { static void findArea ( float a , float b ) { float Area ; Area = ( float ) 3.142 * a * b ; System . out . println ( " Area : ▁ " + Area ) ; } public static void main ( String [ ] args ) { float a = 5 , b = 4 ; findArea ( a , b ) ; } }


"Program to find the Break Even Point | Java program to find Break Even Point ; Function to calculate Break Even Point ; Calculating number of articles to be sold ; Driver Code"
How can the above be solved in Java?

import java . io . * ; import java . lang . * ; class GFG { public static int breakEvenPoint ( int exp1 , int S , int M ) { double earn = S - M ; double exp = exp1 ; double res = Math . ceil ( exp / earn ) ; int res1 = ( int ) res ; return res1 ; } public static void main ( String [ ] args ) { int exp = 3550 , S = 90 , M = 65 ; System . out . println ( breakEvenPoint ( exp , S , M ) ) ; } }


"Program to find the Circumcircle of any regular polygon | Java Program to find the radius of the circumcircle of the given polygon ; Function to find the radius of the circumcircle ; these cannot be negative ; Radius of the circumcircle ; Return the radius ; Driver code ; Find the radius of the circumcircle"
How can the above be solved in Java?

import java . io . * ; class GFG { static float findRadiusOfcircumcircle ( float n , float a ) { if ( n < 0 a < 0 ) return - 1 ; float radius = ( float ) ( a / Math . sqrt ( 2 - ( 2 * Math . cos ( 360 / n ) ) ) ) ; return radius ; } public static void main ( String [ ] args ) { float n = 5 , a = 6 ; System . out . println ( findRadiusOfcircumcircle ( n , a ) ) ; } }


"Program to find the Depreciation of Value | Java program to find depreciation of the value initial value , rate and time are given ; Function to return the depreciation of value ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static float Depreciation ( float v , float r , float t ) { float D = ( float ) ( v * Math . pow ( ( 1 - r / 100 ) , t ) ) ; return D ; } public static void main ( String [ ] args ) { float V1 = 200 , R = 10 , T = 2 ; System . out . print ( Depreciation ( V1 , R , T ) ) ; } }


"Program to find the Hidden Number | Java Program to find the hidden number ; Driver Code ; Getting the size of array ; Getting the array of size n ; Solution ; Finding sum of the array elements ; Dividing sum by size n ; Print x , if found"
How can the above be solved in Java?

public class GFG { public static void main ( String args [ ] ) { int n = 3 ; int a [ ] = { 1 , 2 , 3 } ; int i = 0 ; long sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } long x = sum / n ; if ( x * n == sum ) System . out . println ( x ) ; else System . out . println ( " - 1" ) ; } }


"Program to find the Interior and Exterior Angle of a Regular Polygon | Java program to find the interior and exterior angle of a given polygon ; function to find the interior and exterior angle ; formula to find the interior angle ; formula to find the exterior angle ; Displaying the output ; Driver code ; Function calling"
How can the above be solved in Java?

import java . io . * ; class GFG { static void findAngle ( int n ) { int interiorAngle , exteriorAngle ; interiorAngle = ( n - 2 ) * 180 / n ; exteriorAngle = 360 / n ; System . out . println ( " Interior ▁ angle : ▁ " + interiorAngle ) ; System . out . println ( " Exterior ▁ angle : ▁ " + exteriorAngle ) ; } public static void main ( String [ ] args ) { int n = 10 ; findAngle ( n ) ; } }


"Program to find the LCM of two prime numbers | Java Program to find LCM of two prime numbers ; Function to return the LCM of two prime numbers ; If the two numbers are equal then return any one of a and b ; Else return product of numbers ; Driver code ; Given two numbers ; Function Call"
How can the above be solved in Java?

class GFG { static int findLCMPrime ( int a , int b ) { if ( a == b ) { return a ; } return a * b ; } public static void main ( String [ ] args ) { int a = 3 , b = 5 ; System . out . println ( findLCMPrime ( a , b ) ) ; } }


"Program to find the Nth Composite Number | Java program for the above approach ; Function to find the Nth Composite Numbers using Sieve of Eratosthenes ; Sieve of prime numbers ; Initialize the array to true ; Iterate over the range [ 2 , MAX_SIZE ] ; If IsPrime [ p ] is true ; Iterate over the range [ p * p , MAX_SIZE ] ; Stores the list of composite numbers ; Iterate over the range [ 4 , MAX_SIZE ] ; If i is not prime ; Return Nth Composite Number ; Driver Code"
How can the above be solved in Java?

import java . util . * ; public class GFG { public static int NthComposite ( int N ) { int MAX_SIZE = 1000005 ; boolean [ ] IsPrime = new boolean [ MAX_SIZE ] ; Arrays . fill ( IsPrime , true ) ; for ( int p = 2 ; p * p < MAX_SIZE ; p ++ ) { if ( IsPrime [ p ] == true ) { for ( int i = p * p ; i < MAX_SIZE ; i += p ) IsPrime [ i ] = false ; } } Vector < Integer > Composites = new Vector < Integer > ( ) ; for ( int p = 4 ; p < MAX_SIZE ; p ++ ) if ( ! IsPrime [ p ] ) Composites . add ( p ) ; return Composites . get ( N - 1 ) ; } public static void main ( String args [ ] ) { int N = 4 ; System . out . println ( NthComposite ( N ) ) ; } }


"Program to find the Nth Harmonic Number | Java program to find N - th Harmonic Number ; Function to find N - th Harmonic Number ; H1 = 1 ; loop to apply the forumula Hn = H1 + H2 + H3 ... + Hn - 1 + Hn - 1 + 1 / n ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class GFG { static double nthHarmonic ( int N ) { float harmonic = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { harmonic += ( float ) 1 / i ; } return harmonic ; } public static void main ( String [ ] args ) { int N = 8 ; System . out . print ( nthHarmonic ( N ) ) ; } }


"Program to find the Nth natural number with exactly two bits set | Java Code to find the Nth number with exactly two bits set ; Function to find the Nth number with exactly two bits set ; Keep incrementing until we reach the partition of ' N ' stored in bit_L ; set the rightmost bit based on bit_R ; Driver code"
How can the above be solved in Java?

 class GFG { static void findNthNum ( int N ) { int bit_L = 1 , last_num = 0 ; while ( bit_L * ( bit_L + 1 ) / 2 < N ) { last_num = last_num + bit_L ; bit_L ++ ; } int bit_R = N - last_num - 1 ; System . out . print ( ( 1 << bit_L ) + ( 1 << bit_R ) + "
"); } public static void main ( String [ ] args ) { int N = 13 ; findNthNum ( N ) ; } }


"Program to find the Nth natural number with exactly two bits set | Set 2 | Java program for the above approach ; Function to find the Nth number with exactly two bits set ; Initialize variables ; Initialize the range in which the value of ' a ' is present ; Perform Binary Search ; Find the mid value ; Update the range using the mid value t ; Find b value using a and N ; Print the value 2 ^ a + 2 ^ b ; Driver Code ; Function Call"
How can the above be solved in Java?

import java . util . * ; class GFG { static void findNthNum ( int N ) { int a = 0 , b , left ; int right , mid ; int t , last_num = 0 ; left = 1 ; right = N ; while ( left <= right ) { mid = left + ( right - left ) / 2 ; t = ( mid * ( mid + 1 ) ) / 2 ; if ( t < N ) { left = mid + 1 ; } else if ( t == N ) { a = mid ; break ; } else { a = mid ; right = mid - 1 ; } } t = a - 1 ; b = N - ( t * ( t + 1 ) ) / 2 - 1 ; System . out . print ( ( 1 << a ) + ( 1 << b ) ) ; } public static void main ( String [ ] args ) { int N = 15 ; findNthNum ( N ) ; } }


"Program to find the Nth number of the series 2 , 10 , 24 , 44 , 70. ... . | Java program to find N - th term of the series : ; function to return nth term of the series ; Driver Code ; Taking n as 4 ; Printing the nth term"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static long NthTerm ( long n ) { long x = ( 3 * n * n ) % 1000000009 ; return ( x - n + 1000000009 ) % 1000000009 ; } public static void main ( String args [ ] ) { long N = 4 ; System . out . println ( NthTerm ( N ) ) ; } }


"Program to find the Nth term of series 5 , 10 , 17 , 26 , 37 , 50 , 65 , 82 , ... | Java program to find the N - th term of the series : 5 , 10 , 17 , 26 , 37 , 50 , 65 , 82 , ... ; calculate Nth term of series ; return the final sum ; Driver Function"
How can the above be solved in Java?

import java . util . * ; class solution { static int nthTerm ( int n ) { return ( int ) Math . pow ( n , 2 ) + 2 * n + 2 ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find the Nth term of series 5 , 12 , 21 , 32 , 45. ... . . | Java program to find the N - th term of the series : 5 , 12 , 21 , 32 , 45. . ... . ; calculate Nth term of series ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int nthTerm ( int n ) { return ( int ) Math . pow ( n , 2 ) + 4 * n ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find the Nth term of series | Java program to find N - th term of the series : 9 , 23 , 45 , 75 , 113 , 159. . ... . ; calculate Nth term of series ; Driver code ; Get the value of N ; Find the Nth term and print it"
How can the above be solved in Java?

class GFG { static int nthTerm ( int N ) { return ( ( 3 * N * N ) - ( 6 * N ) + 2 ) ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find the Nth term of the series 0 , 14 , 40 , 78 , 124 , ... | Java program to find the N - th term of the series 0 , 14 , 40 , 78 , 124 . . . ; calculate sum up to Nth term of series ; return the final sum ; Driver code"
How can the above be solved in Java?

import java . util . * ; class solution { static int nthTerm ( int n ) { return 6 * ( int ) Math . pow ( n , 2 ) - 4 * n - 2 ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find the Nth term of the series 0 , 3 / 1 , 8 / 3 , 15 / 5. . ... ... | Java implementation of the approach ; Function to return the nth term of the given series ; nth term ; Driver code"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; import java . io . * ; public class GFG { static void NthTerm ( int n ) { int numerator = ( ( int ) Math . pow ( n , 2 ) ) - 1 ; int denomeanator = 2 * n - 3 ; System . out . println ( numerator + " / " + denomeanator ) ; } public static void main ( String [ ] args ) { int n = 3 ; NthTerm ( n ) ; } }


"Program to find the Nth term of the series 0 , 5 , 14 , 27 , 44 , ... ... . . | Java program to find N - th term of the series : 0 , 5 , 14 , 27 , 44 . . . ; Calculate Nth term of series ; Driver code"
How can the above be solved in Java?

import java . util . * ; class solution { static int nthTerm ( int n ) { return 2 * ( int ) Math . pow ( n , 2 ) - n - 1 ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find the Nth term of the series 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ... | Java program to find the N - th term of the series : 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ; calculate Nth term of series ; Driver code"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int nthTerm ( int n ) { return 4 * ( int ) Math . pow ( n , 2 ) - 7 * n + 3 ; } public static void main ( String args [ ] ) { int N = 4 ; System . out . print ( nthTerm ( N ) ) ; } }


"Program to find the Nth term of the series 3 , 20 , 63 , 144 , 230 , â €¦ â €¦ | Java program to find N - th term of the series : 3 , 20 , 63 , 144 , 230 . ... . ; calculate Nth term of series ; return final sum ; Driver code"
How can the above be solved in Java?

import java . util . * ; class solution { static int nthTerm ( int n ) { return 2 * ( int ) Math . pow ( n , 3 ) + ( int ) Math . pow ( n , 2 ) ; } public static void main ( String arr [ ] ) { int N = 3 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find the Nth term of the series 3 , 7 , 13 , 21 , 31. ... . | Java code to find the Nth term of given series . ; Function to calculate sum ; Return Nth term ; Driver program ; declaration of number of terms ; Get the Nth term"
How can the above be solved in Java?

import java . util . * ; class solution { static long getNthTerm ( long N ) { return ( ( int ) Math . pow ( N , 2 ) + N + 1 ) ; } public static void main ( String arr [ ] ) { long N = 11 ; System . out . println ( getNthTerm ( N ) ) ; } }


"Program to find the Radius of the incircle of the triangle | Java Program to find the radius of the incircle of the given triangle ; Function to find the radius of the incircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of the triangle ; Radius of the incircle ; Return the radius ; Driver code ; Get the sides of the triangle ; Find the radius of the incircle"
How can the above be solved in Java?

import java . io . * ; class GFG { static float findRadiusOfIncircle ( float a , float b , float c ) { if ( a < 0 b < 0 c < 0 ) return - 1 ; float p = ( a + b + c ) / 2 ; float area = ( float ) Math . sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; float radius = area / p ; return radius ; } public static void main ( String [ ] args ) { float a = 2 , b = 2 , c = 3 ; System . out . println ( findRadiusOfIncircle ( a , b , c ) ) ; } }


"Program to find the Roots of Quadratic equation | Java program to find roots of a quadratic equation ; Prints roots of quadratic equation ax * 2 + bx + x ; If a is 0 , then equation is not quadratic , but linear ; else d < 0 ; Driver code ; Function call"
How can the above be solved in Java?

 import java . io . * ; import static java . lang . Math . * ; class Quadratic { static void findRoots ( int a , int b , int c ) { if ( a == 0 ) { System . out . println ( " Invalid " ) ; return ; } int d = b * b - 4 * a * c ; double sqrt_val = sqrt ( abs ( d ) ) ; if ( d > 0 ) { System . out . println ( "Roots are real and different
"); System . out . println ( ( double ) ( - b + sqrt_val ) / ( 2 * a ) + "
" + ( double ) ( - b - sqrt_val ) / ( 2 * a ) ) ; } else if ( d == 0 ) { System . out . println ( "Roots are real and same
"); System . out . println ( - ( double ) b / ( 2 * a ) + "
" + - ( double ) b / ( 2 * a ) ) ; } { System . out . println ( "Roots are complex
"); System . out . println ( - ( double ) b / ( 2 * a ) + " ▁ + ▁ i " + sqrt_val + "
" + - ( double ) b / ( 2 * a ) + " ▁ - ▁ i " + sqrt_val ) ; } } public static void main ( String args [ ] ) { int a = 1 , b = - 7 , c = 12 ; findRoots ( a , b , c ) ; } }


"Program to find the Speed of train as per speed of sound | Java implementation of the approach ; Function to find the Speed of train ; Driver code ; calling Function"
How can the above be solved in Java?

class GFG { static int speedOfTrain ( float X , float Y ) { float Speed ; Speed = 1188 * ( ( X - Y ) / Y ) ; return ( int ) Speed ; } public static void main ( String [ ] args ) { float X = 8f , Y = 7.2f ; int result = ( speedOfTrain ( X , Y ) ) ; System . out . println ( result + " ▁ km / hr " ) ; } }


"Program to find the Type of Triangle from the given Coordinates | Java program to classify a given triangle ; Utility method to return square of x ; Utility method to sort a , b , c ; after this method a <= b <= c ; Utility method to return Square of distance between two points ; Method to classify side ; if all sides are equal ; if any two sides are equal ; Method to classify angle ; If addition of sum of square of two side is less , then acute ; by pythagoras theorem ; Method to classify the triangle by sides and angles ; Find squares of distances between points ; Sort all squares of distances in increasing order ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static class point { int x , y ; point ( ) { } public point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int square ( int x ) { return x * x ; } static int a , b , c ; static void order ( ) { int [ ] copy = new int [ 3 ] ; copy [ 0 ] = a ; copy [ 1 ] = b ; copy [ 2 ] = c ; Arrays . sort ( copy ) ; a = copy [ 0 ] ; b = copy [ 1 ] ; c = copy [ 2 ] ; } static int euclidDistSquare ( point p1 , point p2 ) { return square ( p1 . x - p2 . x ) + square ( p1 . y - p2 . y ) ; } static String getSideClassification ( int a , int b , int c ) { if ( a == b && b == c ) return " Equilateral " ; else if ( a == b b == c ) return " Isosceles " ; else return " Scalene " ; } static String getAngleClassification ( int a , int b , int c ) { if ( a + b > c ) return " acute " ; else if ( a + b == c ) return " right " ; else return " obtuse " ; } static void classifyTriangle ( point p1 , point p2 , point p3 ) { a = euclidDistSquare ( p1 , p2 ) ; b = euclidDistSquare ( p1 , p3 ) ; c = euclidDistSquare ( p2 , p3 ) ; order ( ) ; System . out . println ( " Triangle ▁ is ▁ " + getAngleClassification ( a , b , c ) + " ▁ and ▁ " + getSideClassification ( a , b , c ) ) ; } public static void main ( String [ ] args ) { point p1 , p2 , p3 ; p1 = new point ( 3 , 0 ) ; p2 = new point ( 0 , 4 ) ; p3 = new point ( 4 , 7 ) ; classifyTriangle ( p1 , p2 , p3 ) ; p1 = new point ( 0 , 0 ) ; p2 = new point ( 1 , 1 ) ; p3 = new point ( 1 , 2 ) ; classifyTriangle ( p1 , p2 , p3 ) ; } }


"Program to find the Volume of an irregular tetrahedron | Java implementation of above approach ; Function to find the volume ; Steps to calculate volume of a Tetrahedron using formula ; Driver code ; edge lengths"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static void findVolume ( double u , double v , double w , double U , double V , double W , double b ) { double uPow = Math . pow ( u , 2 ) ; double vPow = Math . pow ( v , 2 ) ; double wPow = Math . pow ( w , 2 ) ; double UPow = Math . pow ( U , 2 ) ; double VPow = Math . pow ( V , 2 ) ; double WPow = Math . pow ( W , 2 ) ; double a = 4 * ( uPow * vPow * wPow ) - uPow * Math . pow ( ( vPow + wPow - UPow ) , 2 ) - vPow * Math . pow ( ( wPow + uPow - VPow ) , 2 ) - wPow * Math . pow ( ( uPow + vPow - WPow ) , 2 ) + ( vPow + wPow - UPow ) * ( wPow + uPow - VPow ) * ( uPow + vPow - WPow ) ; double vol = Math . sqrt ( a ) ; vol /= b ; System . out . printf ( " % .4f " , vol ) ; } public static void main ( String args [ ] ) { double u = 1000 , v = 1000 , w = 1000 ; double U = 3 , V = 4 , W = 5 ; double b = 12 ; findVolume ( u , v , w , U , V , W , b ) ; } }


"Program to find the XOR of ASCII values of characters in a string | Java program to find XOR of ASCII value of characters in String ; Function to find the XOR of ASCII value of characters in String ; store value of first character ; Traverse String to find the XOR ; Return the XOR ; Driver code"
How can the above be solved in Java?

 class GFG { static int XorAscii ( String str , int len ) { int ans = ( str . charAt ( 0 ) ) ; for ( int i = 1 ; i < len ; i ++ ) { ans = ( ans ^ ( ( str . charAt ( i ) ) ) ) ; } return ans ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int len = str . length ( ) ; System . out . print ( XorAscii ( str , len ) + "
"); str = " GfG " ; len = str . length ( ) ; System . out . print ( XorAscii ( str , len ) ) ; } }


"Program to find the common ratio of three numbers | Java implementation of above approach ; Utility function ; Function to print a : b : c ; To print the given proportion in simplest form . ; Driver code ; Get the ratios ; Get ratio a : b1 ; Get ratio b2 : c ; Find the ratio a : b : c"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static void solveProportion ( int a , int b1 , int b2 , int c ) { int A = a * b2 ; int B = b1 * b2 ; int C = b1 * c ; int gcd = __gcd ( __gcd ( A , B ) , C ) ; System . out . print ( A / gcd + " : " + B / gcd + " : " + C / gcd ) ; } public static void main ( String args [ ] ) { int a , b1 , b2 , c ; a = 3 ; b1 = 4 ; b2 = 8 ; c = 9 ; solveProportion ( a , b1 , b2 , c ) ; } }


"Program to find the count of coins of each type from the given ratio | Java implementation of above approach ; function to calculate coin . ; Converting each of them in rupees . As we are given totalRupees = 1800 ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int coin ( int totalRupees , int X , int Y , int Z ) { float one = 0 , fifty = 0 , twentyfive = 0 , result = 0 , total = 0 ; one = X * 1 ; fifty = ( ( Y * 1 ) / 2 ) ; twentyfive = ( ( Z * 1 ) / 4 ) ; total = one + fifty + twentyfive ; result = ( ( totalRupees ) / total ) ; return ( int ) result ; } public static void main ( String [ ] args ) { int totalRupees = 1800 ; int X = 1 , Y = 2 , Z = 4 ; int Rupees = coin ( totalRupees , X , Y , Z ) ; System . out . println ( "1 ▁ rupess ▁ coins ▁ = ▁ " + Rupees * 1 ) ; System . out . println ( "50 ▁ paisa ▁ coins ▁ = ▁ " + Rupees * 2 ) ; System . out . println ( "25 ▁ paisa ▁ coins ▁ = ▁ " + Rupees * 4 ) ; } }


"Program to find the kth character after decrypting a string | Java implementation of the approach ; Function to print kth character of String s after decrypting it ; Get the length of string ; Initialise pointer to character of input string to zero ; Total length of resultant string ; Traverse the string from starting and check if each character is alphabet then increment total_len ; If total_leg equal to k then return string else increment i ; Parse the number ; Update next_total_len ; Get the position of kth character ; Position not found then update position with total_len ; Recursively find the kth position ; Else update total_len by next_total_len ; Return - 1 if character not found ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GfG { static Character findKthChar ( String s , int k ) { int len = s . length ( ) ; int i = 0 ; int total_len = 0 ; while ( i < len ) { if ( Character . isLetter ( s . charAt ( i ) ) ) { total_len ++ ; if ( total_len == k ) return s . charAt ( i ) ; i ++ ; } else { int n = 0 ; while ( i < len && ! Character . isLetter ( s . charAt ( i ) ) ) { n = n * 10 + ( s . charAt ( i ) - '0' ) ; i ++ ; } int next_total_len = total_len * n ; if ( k <= next_total_len ) { int pos = k % total_len ; if ( pos == 0 ) { pos = total_len ; } return findKthChar ( s , pos ) ; } else { total_len = next_total_len ; } } } return ' ▁ ' ; } public static void main ( String [ ] args ) { String s = " ab2c3" ; int k = 5 ; System . out . println ( findKthChar ( s , k ) ) ; } }


"Program to find the last digit of X in base Y | Java Program to find the last digit of X in base Y ; Function to find the last digit of X in base Y ; Driver code"
How can the above be solved in Java?

class GFG { static void last_digit ( int X , int Y ) { System . out . print ( X % Y ) ; } public static void main ( String [ ] args ) { int X = 55 , Y = 3 ; last_digit ( X , Y ) ; } }


"Program to find the length of Latus Rectum of a Hyperbola | Java program for the above approach ; Function to calculate the length of the latus rectum of a hyperbola ; Store the length of major axis ; Store the length of minor axis ; Store the length of the latus rectum ; Return the length of the latus rectum ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class GFG { static double lengthOfLatusRectum ( double A , double B ) { double major = 2.0 * A ; double minor = 2.0 * B ; double latus_rectum = ( minor * minor ) / major ; return latus_rectum ; } public static void main ( String [ ] args ) { double A = 3.0 , B = 2.0 ; System . out . println ( lengthOfLatusRectum ( A , B ) ) ; } }


"Program to find the length of Latus Rectum of a Parabola | Java program for the above approach ; Function to calculate distance between two points ; Calculating distance ; Function to calculate length of the latus rectum of a parabola ; Stores the co - ordinates of the vertex of the parabola ; Stores the co - ordinates of the focus of parabola ; Print the distance between focus and vertex ; Driver Code ; Given a , b & c ; Function call"
How can the above be solved in Java?

class GFG { static class pair { float first ; float second ; public pair ( float first , float second ) { this . first = first ; this . second = second ; } } static float distance ( float x1 , float y1 , float x2 , float y2 ) { return ( float ) Math . sqrt ( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) ) ; } static void lengthOfLatusRectum ( float a , float b , float c ) { pair vertex = new pair ( ( - b / ( 2 * a ) ) , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) ) ; pair focus = new pair ( ( - b / ( 2 * a ) ) , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) ) ; System . out . print ( 4 * distance ( ( float ) focus . first , ( float ) focus . second , ( float ) vertex . first , ( float ) vertex . second ) ) ; } public static void main ( String [ ] args ) { float a = 3 , b = 5 , c = 1 ; lengthOfLatusRectum ( a , b , c ) ; } }


"Program to find the maximum difference between the index of any two different numbers | Java implementation of the approach ; Function to return the maximum difference ; Iteratively check from back ; Different numbers ; Iteratively check from the beginning ; Different numbers ; Driver code"
How can the above be solved in Java?

class GFG { static int findMaximumDiff ( int [ ] a , int n ) { int ind1 = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { if ( a [ 0 ] != a [ i ] ) { ind1 = i ; break ; } } int ind2 = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ n - 1 ] != a [ i ] ) { ind2 = ( n - 1 - i ) ; break ; } } return Math . max ( ind1 , ind2 ) ; } public static void main ( String args [ ] ) { int [ ] a = { 1 , 2 , 3 , 2 , 3 } ; int n = a . length ; System . out . println ( findMaximumDiff ( a , n ) ) ; } }


"Program to find the minimum ( or maximum ) element of an array |  ; Java program to find minimum ( or maximum ) element in an array . ; Driver code"
How can the above be solved in Java?

import java . util . Arrays ; import java . util . Arrays ; class GFG { static int getMin ( int arr [ ] , int n ) { return Arrays . stream ( arr ) . min ( ) . getAsInt ( ) ; } static int getMax ( int arr [ ] , int n ) { return Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 1234 , 45 , 67 , 1 } ; int n = arr . length ; System . out . println ( " Minimum ▁ element ▁ of ▁ array : ▁ " + getMin ( arr , n ) ) ; System . out . println ( " Maximum ▁ element ▁ of ▁ array : ▁ " + getMax ( arr , n ) ) ; } }


"Program to find the minimum ( or maximum ) element of an array | Java program to find minimum ( or maximum ) element in an array . ; If there is single element , return it . Else return minimum of first element and minimum of remaining array . ; If there is single element , return it . Else return maximum of first element and maximum of remaining array . ; Driver code"
How can the above be solved in Java?

 class GFG { static int getMin ( int arr [ ] , int i , int n ) { return ( n == 1 ) ? arr [ i ] : Math . min ( arr [ i ] , getMin ( arr , i + 1 , n - 1 ) ) ; } static int getMax ( int arr [ ] , int i , int n ) { return ( n == 1 ) ? arr [ i ] : Math . max ( arr [ i ] , getMax ( arr , i + 1 , n - 1 ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 1234 , 45 , 67 , 1 } ; int n = arr . length ; System . out . print ( " Minimum ▁ element ▁ of ▁ array : ▁ " + getMin ( arr , 0 , n ) + "
"); System . out . println ( " Maximum ▁ element ▁ of ▁ array : ▁ " + getMax ( arr , 0 , n ) ) ; } }


"Program to find the next prime number | Java implementation of the approach ; Function that returns true if n is prime else returns false ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to return the smallest prime number greater than N ; Base case ; Loop continuously until isPrime returns true for a number greater than n ; Driver code"
How can the above be solved in Java?

class GFG { 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 nextPrime ( int N ) { if ( N <= 1 ) return 2 ; int prime = N ; boolean found = false ; while ( ! found ) { prime ++ ; if ( isPrime ( prime ) ) found = true ; } return prime ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( nextPrime ( N ) ) ; } }


"Program to find the nth Kynea number | JAVA code to find nth Kynea number ; Function to calculate nth kynea number ; Calculate nth kynea number ; Driver Program ; print nth kynea number"
How can the above be solved in Java?

class GFG { static long nthKyneaNumber ( int n ) { return ( ( 1 << ( 2 * n ) ) + ( 1 << ( n + 1 ) ) - 1 ) ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( nthKyneaNumber ( n ) ) ; } }


"Program to find the nth Kynea number | JAVA code to find nth Kynea number ; Function to calculate nth kynea number ; Firstly calculate 2 ^ n + 1 ; Now calculate ( 2 ^ n + 1 ) ^ 2 ; Now calculate ( ( 2 ^ n + 1 ) ^ 2 ) - 2 ; return nth Kynea number ; Driver Program ; print nth kynea number"
How can the above be solved in Java?

class GFG { static long nthKyneaNumber ( int n ) { n = ( 1 << n ) + 1 ; n = n * n ; n = n - 2 ; return n ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( nthKyneaNumber ( n ) ) ; } }


"Program to find the number from given holes | Java implementation of the above approach ; Function that will find out the number ; If number of holes equal 0 then return 1 ; If number of holes equal 0 then return 0 ; If number of holes is more than 0 or 1. ; If number of holes is odd ; Driver code ; Calling Function"
How can the above be solved in Java?

import java . io . * ; class GFG { static void printNumber ( int holes ) { if ( holes == 0 ) System . out . print ( "1" ) ; else if ( holes == 1 ) System . out . print ( "0" ) ; else { int rem = 0 , quo = 0 ; rem = holes % 2 ; quo = holes / 2 ; if ( rem == 1 ) System . out . print ( "4" ) ; for ( int i = 0 ; i < quo ; i ++ ) System . out . print ( "8" ) ; } } public static void main ( String [ ] args ) { int holes = 3 ; printNumber ( holes ) ; } }


"Program to find the number of region in Planar Graph | Java implementation of the approach ; Function to return the number of regions in a Planar Graph ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int Regions ( int Vertices , int Edges ) { int R = Edges + 2 - Vertices ; return R ; } public static void main ( String [ ] args ) { int V = 5 , E = 7 ; System . out . println ( Regions ( V , E ) ) ; } }


"Program to find the percentage of difference between two numbers | Java program to calculate the percentage ; Function to calculate the percentage ; Driver Code ; Function calling"
How can the above be solved in Java?

class GFG { static int percent ( int a , int b ) { float result = 0 ; result = ( ( b - a ) * 100 ) / a ; return ( int ) result ; } public static void main ( String [ ] args ) { int a = 20 , b = 25 ; System . out . println ( percent ( a , b ) + " % " ) ; } }


"Program to find the product of ASCII values of characters in a string | Java program to find product of ASCII value of characters in string ; Function to find product of ASCII value of characters in string ; Traverse string to find the product ; Return the product ; Driver Code"
How can the above be solved in Java?

class GFG { static long productAscii ( String str ) { long prod = 1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { prod *= str . charAt ( i ) ; } return prod ; } public static void main ( String [ ] args ) { String str = " GfG " ; System . out . println ( productAscii ( str ) ) ; } }


"Program to find the profit or loss when CP of N items is equal to SP of M items | Java implementation of above formula ; Function to calculate Profit or loss ; Driver Code"
How can the above be solved in Java?

public class GFG { static void profitLoss ( int N , int M ) { if ( N == M ) System . out . print ( " No ▁ Profit ▁ nor ▁ Loss " ) ; else { float result = 0 ; result = ( float ) ( Math . abs ( N - M ) ) / M ; if ( N - M < 0 ) System . out . print ( " Loss ▁ = ▁ - " + result * 100 + " % " ) ; else System . out . print ( " Profit ▁ = ▁ " + result * 100 + " % " ) ; } } public static void main ( String [ ] args ) { int N = 8 , M = 9 ; profitLoss ( N , M ) ; } }


"Program to find the quantity after mixture replacement | Java code using above Formula . ; Function to calculate the Remaining amount . ; calculate Right hand Side ( RHS ) . ; calculate Amount left by multiply it with original value . ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class GFG { static double Mixture ( int X , int Y , int Z ) { double result1 = 0.0 , result = 0.0 ; result1 = ( ( X - Y ) / ( float ) X ) ; result = Math . pow ( result1 , Z ) ; result = result * X ; return result ; } public static void main ( String [ ] args ) { int X = 10 , Y = 2 , Z = 2 ; System . out . println ( ( float ) Mixture ( X , Y , Z ) + " ▁ litres " ) ; } }


"Program to find the rate percentage from compound interest of consecutive years | Java implementation of the approach ; Function to return the required rate percentage ; Driver code"
How can the above be solved in Java?

class GFG { static int Rate ( int N1 , int N2 ) { float rate = ( N2 - N1 ) * 100 / N1 ; return ( int ) rate ; } public static void main ( String [ ] args ) { int N1 = 100 , N2 = 120 ; System . out . println ( Rate ( N1 , N2 ) + " ▁ % " ) ; } }


"Program to find the side of the Octagon inscribed within the square | Java Program to find the side of the octagon which can be inscribed within the square ; Function to find the side of the octagon ; side cannot be negative ; side of the octagon ; Driver code ; Get he square side ; Find the side length of the square"
How can the above be solved in Java?

import java . io . * ; class GFG { static double octaside ( double a ) { if ( a < 0 ) return - 1 ; double s = a / ( Math . sqrt ( 2 ) + 1 ) ; return s ; } public static void main ( String [ ] args ) { double a = 4 ; System . out . println ( octaside ( a ) ) ; } }


"Program to find the smallest element among three elements | Java implementation to find the smallest of three elements"
How can the above be solved in Java?

import java . io . * ; class GFG { public static void main ( String [ ] args ) { int a = 5 , b = 7 , c = 10 ; if ( a <= b && a <= c ) System . out . println ( a + " ▁ is ▁ the ▁ smallest " ) ; else if ( b <= a && b <= c ) System . out . println ( b + " ▁ is ▁ the ▁ smallest " ) ; else System . out . println ( c + " ▁ is ▁ the ▁ smallest " ) ; } }


"Program to find the sum of the series 1 + x + x ^ 2 + x ^ 3 + . . + x ^ n | Java implementation to find the sum of series 1 + x ^ 2 + x ^ 3 + ... . + x ^ n ; Java code to print the sum of the given series ; First Term ; Loop to print the N terms of the series and compute their sum ; Driver Code"
How can the above be solved in Java?

class GFG { static double sum ( int x , int n ) { double i , total = 1.0 , multi = x ; System . out . print ( "1 ▁ " ) ; for ( i = 1 ; i < n ; i ++ ) { total = total + multi ; System . out . print ( multi ) ; System . out . print ( " ▁ " ) ; multi = multi * x ; } System . out . println ( ) ; return total ; } public static void main ( String [ ] args ) { int x = 2 ; int n = 5 ; System . out . printf ( " % .2f " , sum ( x , 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"
How can the above be solved in Java?

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 ) ) ; } }


"Program to find the surface area of the square pyramid | Java program to find the surface area Of Square pyramid ; function to find the surface area ; Driver program ; surface area of the square pyramid"
How can the above be solved in Java?

import java . io . * ; class GFG { static int surfaceArea ( int b , int s ) { return 2 * b * s + ( int ) Math . pow ( b , 2 ) ; } public static void main ( String [ ] args ) { int b = 3 , s = 4 ; System . out . println ( surfaceArea ( b , s ) ) ; } }


"Program to find the time remaining for the day to complete | Java program to Number of pairs of lines having integer intersection points ; Function to find the remaining time ; Formula for total remaining minutes = 1440 - 60 h - m ; Remaining hours ; Remaining minutes ; Driver code ; Current time ; Get the remaining time"
How can the above be solved in Java?

 class GFG { static void remainingTime ( int h , int m ) { int totalMin , hoursRemaining , minRemaining ; totalMin = 1440 - 60 * h - m ; hoursRemaining = totalMin / 60 ; minRemaining = totalMin % 60 ; System . out . print ( hoursRemaining + " : : " + minRemaining + "
"); } public static void main ( String [ ] args ) { int h = 0 , m = 1 ; remainingTime ( h , m ) ; } }


"Program to find the value of P ( N + r ) for a polynomial of a degree N such that P ( i ) = 1 for 1 Ã ¢ â €°¤ i Ã ¢ â €°¤ N and P ( N + 1 ) = a | Java program for the above approach ; Function to calculate factorial of N ; Base Case ; Otherwise , recursively calculate the factorial ; Function to find the value of P ( n + r ) for polynomial P ( X ) ; Stores the value of k ; Store the required answer ; Iterate in the range [ 1 , N ] and multiply ( n + r - i ) with answer ; Add the constant value C as 1 ; Return the result ; Driver Code"
How can the above be solved in Java?

import java . util . * ; class GFG { static int fact ( int n ) { if ( n == 1 n == 0 ) return 1 ; else return n * fact ( n - 1 ) ; } static int findValue ( int n , int r , int a ) { int k = ( a - 1 ) / fact ( n ) ; int answer = k ; for ( int i = 1 ; i < n + 1 ; i ++ ) answer = answer * ( n + r - i ) ; answer = answer + 1 ; return answer ; } public static void main ( String args [ ] ) { int N = 1 ; int A = 2 ; int R = 3 ; System . out . print ( findValue ( N , R , A ) ) ; } }


"Program to find the value of sin ( nÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬¦½ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬¹ ÃƒÆ ’ Ã ¢ â ‚¬¦ Ãƒ ¢ Ã ¢ â € š ¬ Ã … â € œ ) | Java Program to find the value of sin ( n ? ) ; This function use to calculate the binomial coefficient upto 15 ; use simple DP to find coefficient ; Function to find the value of ; find cosTheta from sinTheta ; store required answer ; use to toggle sign in sequence . ; Driver code"
How can the above be solved in Java?

public class GFG { private static final int MAX = 16 ; static long nCr [ ] [ ] = new long [ MAX ] [ MAX ] ; static void binomial ( ) { for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ] ; } } } static double findCosNTheta ( double sinTheta , int n ) { double cosTheta = Math . sqrt ( 1 - sinTheta * sinTheta ) ; double ans = 0 ; long toggle = 1 ; for ( int i = 1 ; i <= n ; i += 2 ) { ans = ans + nCr [ n ] [ i ] * Math . pow ( cosTheta , n - i ) * Math . pow ( sinTheta , i ) * toggle ; toggle = toggle * - 1 ; } return ans ; } public static void main ( String args [ ] ) { binomial ( ) ; double sinTheta = 0.5 ; int n = 10 ; System . out . println ( findCosNTheta ( sinTheta , n ) ) ; } }


"Program to find the value of tan ( nÎ ˜ ) | Java program to find the value of cos ( n - theta ) ; This function use to calculate the binomial coefficient upto 15 ; use simple DP to find coefficient ; Function to find the value of ; store required answer ; use to toggle sign in sequence . ; calculate numerator ; calculate denominator ; Driver code"
How can the above be solved in Java?

public class GFG { private static final int MAX = 16 ; static long nCr [ ] [ ] = new long [ MAX ] [ MAX ] ; static void binomial ( ) { for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ] ; } } } static double findTanNTheta ( double tanTheta , int n ) { double ans = 0 , numerator = 0 , denominator = 0 ; long toggle = 1 ; for ( int i = 1 ; i <= n ; i += 2 ) { numerator = numerator + nCr [ n ] [ i ] * Math . pow ( tanTheta , i ) * toggle ; toggle = toggle * - 1 ; } denominator = 1 ; toggle = - 1 ; for ( int i = 2 ; i <= n ; i += 2 ) { numerator = numerator + nCr [ n ] [ i ] * Math . pow ( tanTheta , i ) * toggle ; toggle = toggle * - 1 ; } ans = numerator / denominator ; return ans ; } public static void main ( String args [ ] ) { binomial ( ) ; double tanTheta = 0.3 ; int n = 10 ; System . out . println ( findTanNTheta ( tanTheta , n ) ) ; } }


"Program to find third side of triangle using law of cosines | Java program to find third side of triangle using law of cosines ; Function to calculate cos value of angle c ; Converting degrees to radian ; Maps the sum along the series ; Holds the actual value of sin ( n ) ; Function to find third side ; Driver code ; function call"
How can the above be solved in Java?

class GFG { static float cal_cos ( float n ) { float accuracy = 0.0001f , x1 ; float denominator , cosx , cosval ; n = n * ( 3.142f / 180.0f ) ; x1 = 1 ; cosx = x1 ; cosval = ( float ) Math . cos ( n ) ; int i = 1 ; do { denominator = 2 * i * ( 2 * i - 1 ) ; x1 = - x1 * n * n / denominator ; cosx = cosx + x1 ; i = i + 1 ; } while ( accuracy <= Math . abs ( cosval - cosx ) ) ; return cosx ; } static float third_side ( int a , int b , float c ) { float angle = cal_cos ( c ) ; return ( float ) Math . sqrt ( ( a * a ) + ( b * b ) - 2 * a * b * angle ) ; } public static void main ( String [ ] args ) { float c = 49 ; int a = 5 , b = 8 ; System . out . print ( Math . round ( third_side ( a , b , c ) * 100000.0 ) / 100000.0 ) ; } }


"Program to find total number of edges in a Complete Graph | Java implementation to find the number of edges in a complete graph ; Function to find the total number of edges in a complete graph with N vertices ; Driver Code"
How can the above be solved in Java?

class GFG { static int totEdge ( int n ) { int result = 0 ; result = ( n * ( n - 1 ) ) / 2 ; return result ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( totEdge ( n ) ) ; } }


"Program to find volume and surface area of pentagonal prism | Java program to find surface area and volume of the Pentagonal Prism ; function for surface area ; function for VOlume ; Driver function"
How can the above be solved in Java?

import java . util . * ; class solution { static float surfaceArea ( float a , float b , float h ) { return 5 * a * b + 5 * b * h ; } static float volume ( float b , float h ) { return ( 5 * b * h ) / 2 ; } public static void main ( String arr [ ] ) { float a = 5 ; float b = 3 ; float h = 7 ; System . out . println ( " surface ▁ area = ▁ " + surfaceArea ( a , b , h ) + " , ▁ " ) ; System . out . println ( " volume = ▁ " + volume ( b , h ) ) ; } }


"Program to find weighted median of a given array | Java program for the above approach ; Function to calculate weighted median ; Store pr of arr [ i ] and W [ i ] ; Sort the list of pr w . r . t . to their arr [ ] values ; If N is odd ; Traverse the set pr from left to right ; Update sums ; If sum becomes > 0.5 ; If N is even ; For lower median traverse the set pr from left ; Update sums ; When sum >= 0.5 ; For upper median traverse the set pr from right ; Update sums ; When sum >= 0.5 ; Driver Code ; Given array arr [ ] ; Given weights W [ ] ; Function Call"
How can the above be solved in Java?

 import java . util . * ; class GFG { static class Pair implements Comparable < Pair > { int first ; double second ; Pair ( int f , double s ) { first = f ; second = s ; } @ Override public int compareTo ( Pair o ) { if ( this . second > o . second ) return 1 ; else if ( this . second == o . second ) return 0 ; return - 1 ; } } static void weightedMedian ( Vector < Integer > arr , Vector < Double > W ) { Vector < Pair > pr = new Vector < > ( ) ; for ( int index = 0 ; index < arr . size ( ) ; index ++ ) pr . add ( new Pair ( arr . get ( index ) , W . get ( index ) ) ) ; Collections . sort ( pr ) ; if ( arr . size ( ) % 2 != 0 ) { float sums = 0 ; for ( Pair element : pr ) { sums += element . second ; if ( sums > 0.5 ) System . out . print ( " The ▁ Weighted ▁ Median ▁ is ▁ element ▁ " + element . first + "
"); } } else { double sums = 0 ; for ( Pair element : pr ) { sums += element . second ; if ( sums <= 0.5 ) { System . out . print ( " Lower ▁ Weighted ▁ Median ▁ is ▁ element ▁ " + element . first + "
"); break ; } } sums = 0 ; for ( int index = pr . size ( ) - 1 ; index >= 0 ; index -- ) { int element = pr . get ( index ) . first ; double weight = pr . get ( index ) . second ; sums += weight ; if ( sums >= 0.5 ) { System . out . print ( " Upper ▁ Weighted ▁ Median ▁ is ▁ element ▁ " + element ) ; break ; } } } } public static void main ( String [ ] args ) { Vector < Integer > arr = new Vector < > ( ) ; arr . add ( 4 ) ; arr . add ( 1 ) ; arr . add ( 3 ) ; arr . add ( 2 ) ; Vector < Double > W = new Vector < > ( ) ; W . add ( 0.25 ) ; W . add ( 0.49 ) ; W . add ( 0.25 ) ; W . add ( 0.01 ) ; weightedMedian ( arr , W ) ; } }


"Program to generate an array having convolution of two given arrays | Java program for the above approach ; Function to generate a convolution array of two given arrays ; Stores the size of arrays ; Stores the final array ; Traverse the two given arrays ; Update the convolution array ; Print the convolution array c [ ] ; Driver Code"
How can the above be solved in Java?

import java . util . * ; class GFG { static int MOD = 998244353 ; static void findConvolution ( int [ ] a , int [ ] b ) { int n = a . length , m = b . length ; int [ ] c = new int [ ( n + m - 1 ) ] ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { c [ i + j ] += ( a [ i ] * b [ j ] ) % MOD ; } } for ( int k = 0 ; k < c . length ; ++ k ) { c [ k ] %= MOD ; System . out . print ( c [ k ] + " ▁ " ) ; } } public static void main ( String args [ ] ) { int [ ] A = { 1 , 2 , 3 , 4 } ; int [ ] B = { 5 , 6 , 7 , 8 , 9 } ; findConvolution ( A , B ) ; } }


"Program to get the Sum of series : 1 | Java program to get the sum of the series ; Function to get the series ; Computing sum of remaining n - 1 terms . ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class GFG { static double Series ( double x , int n ) { double sum = 1 , term = 1 , fct = 1 ; double p = 1 , multi = 1 ; for ( int i = 1 ; i < n ; i ++ ) { fct = fct * multi * ( multi + 1 ) ; p = p * x * x ; term = ( - 1 ) * term ; multi += 2 ; sum = sum + ( term * p ) / fct ; } return sum ; } public static void main ( String args [ ] ) { double x = 9 ; int n = 10 ; System . out . printf ( " % .4f " , Series ( x , n ) ) ; } }


"Program to get the Sum of series : 1 | Java program to get the sum of the series ; Function to get the series ; Sum of n - 1 terms starting from 2 nd term ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class MathSeries { static double Series ( double x , int n ) { double sum = 1 , term = 1 , fct , j , y = 2 , m ; int i ; for ( i = 1 ; i < n ; i ++ ) { fct = 1 ; for ( j = 1 ; j <= y ; j ++ ) { fct = fct * j ; } term = term * ( - 1 ) ; m = Math . pow ( x , y ) / fct ; m = m * term ; sum = sum + m ; y += 2 ; } return sum ; } public static void main ( String [ ] args ) { double x = 3 ; int n = 4 ; System . out . println ( Math . round ( Series ( x , n ) * 10000.0 ) / 10000.0 ) ; } }


"Program to implement ASCII lookup table | Java implementation for ASCII table lookup ; Function to convert decimal value to equivalent octal value ; Function to convert decimal value to equivalent hexadecimal value ; Function to convert decimal value to equivalent HTML value ; ASCII lookup table ; Implicit typecasting converts the character into it 's equivalent ASCII ; driver function"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; class GeeksforGeeks { static int Octal ( int decimal ) { int octal = 0 ; String temp = " " ; while ( decimal > 0 ) { int remainder = decimal % 8 ; temp = remainder + temp ; decimal /= 8 ; } for ( int i = 0 ; i < temp . length ( ) ; i ++ ) octal = ( octal * 10 ) + ( temp . charAt ( i ) - '0' ) ; return octal ; } static String Hexadecimal ( int decimal ) { String hex = " " ; while ( decimal > 0 ) { int remainder = decimal % 16 ; if ( remainder >= 0 && remainder <= 9 ) hex = remainder + hex ; else hex = ( char ) ( ' A ' + remainder % 10 ) + hex ; decimal /= 16 ; } return hex ; } static String HTML ( int decimal ) { String html = " " ; html = html + decimal ; html = " & # " + html + " ; " ; return html ; } static void ASCIIlookuptable ( char ch ) { int decimal = ch ; System . out . println ( " Octal ▁ value : ▁ " + Octal ( decimal ) ) ; System . out . println ( " Decimal ▁ value : ▁ " + decimal ) ; System . out . println ( " Hexadecimal ▁ value : ▁ " + Hexadecimal ( decimal ) ) ; System . out . println ( " HTML ▁ value : ▁ " + HTML ( decimal ) ) ; } public static void main ( String args [ ] ) { char ch = ' @ ' ; ASCIIlookuptable ( ch ) ; } }


"Program to implement Collatz Conjecture | Jav program to implement Collatz Conjecture ; Function to find if n reaches to 1 or not . ; If there is a cycle formed , we can 't r  reach 1. ; If n is odd then pass n = 3 n + 1 else n = n / 2 ; Wrapper over isToOneRec ( ) ; To store numbers visited using recursive calls . ; Drivers code"
How can the above be solved in Java?

import java . util . * ; class GFG { static boolean isToOneRec ( int n , HashSet < Integer > s ) { if ( n == 1 ) { return true ; } if ( s . contains ( n ) ) { return false ; } return ( n % 2 == 1 ) ? isToOneRec ( 3 * n + 1 , s ) : isToOneRec ( n / 2 , s ) ; } static boolean isToOne ( int n ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; return isToOneRec ( n , s ) ; } public static void main ( String [ ] args ) { int n = 5 ; if ( isToOne ( n ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to implement Collatz Conjecture | Java program to implement Collatz Conjecture ; Function to find if n reaches to 1 or not . ; Return true if n is positive ; Drivers code"
How can the above be solved in Java?

class GFG { static boolean isToOne ( int n ) { return ( n > 0 ) ; } public static void main ( String [ ] args ) { int n = 5 ; if ( isToOne ( n ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }


"Program to implement Inverse Interpolation using Lagrange Formula | Java code for solving inverse interpolation ; Consider a structure to keep each pair of x and y together ; Function to calculate the inverse interpolation ; Initialize final x ; Calculate each term of the given formula ; Add term to final result ; Driver Code ; Sample dataset of 4 points Here we find the value of x when y = 4.5 ; Size of dataset ; Sample y value ; Using the Inverse Interpolation function to find the value of x when y = 4.5"
How can the above be solved in Java?

class GFG { static class Data { double x , y ; public Data ( double x , double y ) { super ( ) ; this . x = x ; this . y = y ; } } ; static double inv_interpolate ( Data [ ] d , int n , double y ) { double x = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) { double xi = d [ i ] . x ; for ( j = 0 ; j < n ; j ++ ) { if ( j != i ) { xi = xi * ( y - d [ j ] . y ) / ( d [ i ] . y - d [ j ] . y ) ; } } x += xi ; } return x ; } public static void main ( String [ ] args ) { Data [ ] d = { new Data ( 1.27 , 2.3 ) , new Data ( 2.25 , 2.95 ) , new Data ( 2.5 , 3.5 ) , new Data ( 3.6 , 5.1 ) } ; int n = 4 ; double y = 4.5 ; System . out . printf ( " Value ▁ of ▁ x ▁ at ▁ y ▁ = ▁ 4.5 ▁ : ▁ % .5f " , inv_interpolate ( d , n , y ) ) ; } }


"Program to implement Simpson 's 3/8 rule | Java Code to implement Simpson 's rule ; Given function to be integrated ; Function to perform calculations ; Calculates value till integral limit ; Driver program to test above function"
How can the above be solved in Java?

import java . util . * ; class GFG { static float func ( float x ) { return ( 1 / ( 1 + x * x ) ) ; } static float calculate ( float lower_limit , float upper_limit , int interval_limit ) { float value ; float interval_size = ( upper_limit - lower_limit ) / interval_limit ; float sum = func ( lower_limit ) + func ( upper_limit ) ; for ( int i = 1 ; i < interval_limit ; i ++ ) { if ( i % 3 == 0 ) sum = sum + 2 * func ( lower_limit + i * interval_size ) ; else sum = sum + 3 * func ( lower_limit + i * interval_size ) ; } return ( 3 * interval_size / 8 ) * sum ; } public static void main ( String [ ] args ) { int interval_limit = 10 ; float lower_limit = 1 ; float upper_limit = 10 ; float integral_res = calculate ( lower_limit , upper_limit , interval_limit ) ; System . out . println ( integral_res ) ; } }


"Program to implement standard deviation of grouped data | Java program to implement standard deviation of grouped data . ; Function to find mean of grouped data . ; Function to find standard deviation of grouped data . ; Formula to find standard deviation deviation of grouped data . ; Driver function . ; Declare and initialize the lower limit of interval . ; Declare and initialize the upper limit of interval . ; Calculating the size of array ."
How can the above be solved in Java?

import java . io . * ; class GFG { static float mean ( float mid [ ] , int freq [ ] , int n ) { float sum = 0 , freqSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + mid [ i ] * freq [ i ] ; freqSum = freqSum + freq [ i ] ; } return sum / freqSum ; } static float groupedSD ( float lower_limit [ ] , float upper_limit [ ] , int freq [ ] , int n ) { float mid [ ] = new float [ n ] ; float sum = 0 , freqSum = 0 , sd ; for ( int i = 0 ; i < n ; i ++ ) { mid [ i ] = ( lower_limit [ i ] + upper_limit [ i ] ) / 2 ; sum = sum + freq [ i ] * mid [ i ] * mid [ i ] ; freqSum = freqSum + freq [ i ] ; } sd = ( float ) Math . sqrt ( ( sum - freqSum * mean ( mid , freq , n ) * mean ( mid , freq , n ) ) / ( freqSum - 1 ) ) ; return sd ; } public static void main ( String [ ] args ) { float lower_limit [ ] = { 50 , 61 , 71 , 86 , 96 } ; float upper_limit [ ] = { 60 , 70 , 85 , 95 , 100 } ; int freq [ ] = { 9 , 7 , 9 , 12 , 8 } ; int n = lower_limit . length ; System . out . println ( groupedSD ( lower_limit , upper_limit , freq , n ) ) ; } }


"Program to implement standard error of mean | Java Program to implement standard error of mean . ; Function to find sample mean . ; loop to calculate sum of array elements . ; Function to calculate sample standard deviation . ; Function to calculate sample error . ; Formula to find sample error . ; Driver function"
How can the above be solved in Java?

class GFG { static float mean ( float arr [ ] , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; return sum / n ; } static float SSD ( float arr [ ] , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + ( arr [ i ] - mean ( arr , n ) ) * ( arr [ i ] - mean ( arr , n ) ) ; return ( float ) Math . sqrt ( sum / ( n - 1 ) ) ; } static float sampleError ( float arr [ ] , int n ) { return SSD ( arr , n ) / ( float ) Math . sqrt ( n ) ; } public static void main ( String [ ] args ) { float arr [ ] = { 78.53f , 79.62f , 80.25f , 81.05f , 83.21f , 83.46f } ; int n = arr . length ; System . out . println ( sampleError ( arr , n ) ) ; } }


"Program to insert dashes between two adjacent odd digits in given Number | Java program to implement the above approach ; Function to check if char ch is odd or not ; Function to insert dash - between any 2 consecutive digit in string str ; Traverse the string character by character ; Compare every consecutive character with the odd value ; Print the resultant string ; Driver Code ; Given number in form of string ; Function call"
How can the above be solved in Java?

class GFG { static boolean checkOdd ( char ch ) { return ( ( ch - '0' ) & 1 ) != 0 ? true : false ; } static String Insert_dash ( String num_str ) { StringBuilder result_str = new StringBuilder ( num_str ) ; for ( int x = 0 ; x < num_str . length ( ) - 1 ; x ++ ) { if ( checkOdd ( num_str . charAt ( x ) ) && checkOdd ( num_str . charAt ( x + 1 ) ) ) { result_str . insert ( x + 1 , " - " ) ; num_str = result_str . toString ( ) ; x ++ ; } } return result_str . toString ( ) ; } public static void main ( String [ ] args ) { String str = "1745389" ; System . out . println ( Insert_dash ( str ) ) ; } }


"Program to perform a letter frequency attack on a monoalphabetic substitution cipher | Java program for the above approach ; Function to decrypt a monoalphabetic substitution cipher using the letter frequency attack ; Stores final 5 possible deciphered plaintext ; Store the frequency of each letter in cipher text ; Stores the frequency of each letter in cipher text in descending order ; Store which alphabet is used already ; Traverse the String S ; Copy the frequency array ; Stores the String formed from concatanating the english letters in the decreasing frequency in the english language ; Sort the array in descending order ; Itearate over the range [ 0 , 5 ] ; Iterate over the range [ 0 , 26 ] ; Store the numerical equivalent of letter at ith index of array letter_frequency ; Calculate the probable shift used in monoalphabetic cipher ; Temporary String to generate one plaintext at a time ; Generate the probable ith plaintext String using the shift calculated above ; Insert whitespaces as it is ; Shift the kth letter of the cipher by x ; Add the kth calculated / shifted letter to temporary String ; Print the generated 5 possible plaintexts ; Driver Code ; Given String ; Function Call"
How can the above be solved in Java?

 import java . util . * ; class GFG { static void printString ( String S , int N ) { String [ ] plaintext = new String [ 5 ] ; int freq [ ] = new int [ 26 ] ; int freqSorted [ ] = new int [ 26 ] ; int Used [ ] = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) != ' ▁ ' ) { freq [ S . charAt ( i ) - ' A ' ] ++ ; } } for ( int i = 0 ; i < 26 ; i ++ ) { freqSorted [ i ] = freq [ i ] ; } String T = " ETAOINSHRDLCUMWFGYPBVKJXQZ " ; Arrays . sort ( freqSorted ) ; freqSorted = reverse ( freqSorted ) ; for ( int i = 0 ; i < 5 ; i ++ ) { int ch = - 1 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( freqSorted [ i ] == freq [ j ] && Used [ j ] == 0 ) { Used [ j ] = 1 ; ch = j ; break ; } } if ( ch == - 1 ) break ; int x = T . charAt ( i ) - ' A ' ; x = x - ch ; String curr = " " ; for ( int k = 0 ; k < N ; k ++ ) { if ( S . charAt ( k ) == ' ▁ ' ) { curr += ( char ) ' ▁ ' ; continue ; } int y = S . charAt ( k ) - ' A ' ; y += x ; if ( y < 0 ) y += 26 ; if ( y > 25 ) y -= 26 ; curr += ( char ) ( ' A ' + y ) ; } plaintext [ i ] = curr ; } for ( int i = 0 ; i < 5 ; i ++ ) { System . out . print ( plaintext [ i ] + "
"); } } static int [ ] reverse ( int a [ ] ) { int i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } public static void main ( String [ ] args ) { String S = " B ▁ TJNQMF ▁ NFTTBHF " ; int N = S . length ( ) ; printString ( S , N ) ; } }


"Program to print Arithmetic Progression series | Java Program to print an arithmetic progression series ; Printing AP by simply adding d to previous term . ; Driver code ; starting number ; Common difference ; N th term to be find"
How can the above be solved in Java?

class GFG { static void printAP ( int a , int d , int n ) { int curr_term ; curr_term = a ; for ( int i = 1 ; i <= n ; i ++ ) { System . out . print ( curr_term + " ▁ " ) ; curr_term = curr_term + d ; } } public static void main ( String [ ] args ) { int a = 2 ; int d = 1 ; int n = 5 ; printAP ( a , d , n ) ; } }


"Program to print Collatz Sequence | Java program to print Collatz sequence ; We simply follow steps while we do not reach 1 ; If n is odd ; If even ; Print 1 at the end ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static void printCollatz ( int n ) { while ( n != 1 ) { System . out . print ( n + " ▁ " ) ; if ( ( n & 1 ) == 1 ) n = 3 * n + 1 ; else n = n / 2 ; } System . out . print ( n ) ; } public static void main ( String [ ] args ) { printCollatz ( 6 ) ; } }