"Program to calculate area of inner circle which passes through center of outer circle and touches its circumference | Java implementation of the above approach ; Function calculate the area of the inner circle ; the radius cannot be negative ; area of the circle ; Driver Code"
How can the above be solved in Java?

class GFG { static double innerCirclearea ( double radius ) { if ( radius < 0 ) { return - 1 ; } double r = radius / 2 ; double Area = ( 3.14 * Math . pow ( r , 2 ) ) ; return Area ; } public static void main ( String arr [ ] ) { double radius = 4 ; System . out . println ( " Area ▁ of ▁ circle ▁ c2 ▁ = ▁ " + innerCirclearea ( radius ) ) ; } }


"Program to calculate distance between two points in 3 D | Java program to find distance between two points in 3 D . ; Function for distance ; Driver code ; function call for distance"
How can the above be solved in Java?

import java . io . * ; import java . lang . Math ; class GFG { static void distance ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ) { double d = Math . pow ( ( Math . pow ( x2 - x1 , 2 ) + Math . pow ( y2 - y1 , 2 ) + Math . pow ( z2 - z1 , 2 ) * 1.0 ) , 0.5 ) ; System . out . println ( " Distance ▁ is ▁ " + d ) ; return ; } public static void main ( String [ ] args ) { float x1 = 2 ; float y1 = - 5 ; float z1 = 7 ; float x2 = 3 ; float y2 = 4 ; float z2 = 5 ; distance ( x1 , y1 , z1 , x2 , y2 , z2 ) ; } }


"Program to calculate distance between two points | Java code to compute distance ; Function to calculate distance ; Calculating distance ; Driver code"
How can the above be solved in Java?

class GFG { static double distance ( int x1 , int y1 , int x2 , int y2 ) { return Math . sqrt ( Math . pow ( x2 - x1 , 2 ) + Math . pow ( y2 - y1 , 2 ) * 1.0 ) ; } public static void main ( String [ ] args ) { System . out . println ( Math . round ( distance ( 3 , 4 , 4 , 3 ) * 100000.0 ) / 100000.0 ) ; } }


"Program to calculate expected increase in price P after N consecutive days | Java program for the above approach ; Function to find the increased value of P after N days ; Expected value of the number P after N days ; Print the expected value ; Driver code"
How can the above be solved in Java?

class GFG { static void expectedValue ( int P , int a , int b , int N ) { double expValue = P + ( N * 0.5 * ( a + b ) ) ; System . out . print ( expValue ) ; } public static void main ( String [ ] args ) { int P = 3000 , a = 20 , b = 10 , N = 30 ; expectedValue ( P , a , b , N ) ; } }


"Program to calculate gross salary of a person | Java program to implement the above approach ; Function to calculate the salary of the person ; Condition to compute the allowance for the person ; Calculate gross salary ; Driver Code ; Function call"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; class GFG { static int computeSalary ( int basic , char grade ) { double allowance ; double hra , da , pf ; hra = 0.2 * basic ; da = 0.5 * basic ; pf = 0.11 * basic ; if ( grade == ' A ' ) { allowance = 1700.0 ; } else if ( grade == ' B ' ) { allowance = 1500.0 ; } else { allowance = 1300.0 ; } double gross ; gross = Math . round ( basic + hra + da + allowance - pf ) ; return ( int ) gross ; } public static void main ( String [ ] args ) { int basic = 10000 ; char grade = ' A ' ; System . out . println ( computeSalary ( basic , grade ) ) ; } }


"Program to calculate length of diagonal of a square | Java program for the above approach ; Function to find the length of the diagonal of a square of a given side ; Driver Code"
How can the above be solved in Java?

import java . util . * ; class GFG { static double findDiagonal ( double s ) { return ( double ) Math . sqrt ( 2 ) * s ; } public static void main ( String [ ] args ) { double S = 10 ; System . out . print ( findDiagonal ( S ) ) ; } }


"Program to calculate sum of an Infinite Arithmetic | Java program for the above approach ; Function to find the sum of the infinite AGP ; Stores the sum of infinite AGP ; Print the required sum ; Driver Code"
How can the above be solved in Java?

class GFG { static void sumOfInfiniteAGP ( double a , double d , double r ) { double ans = a / ( 1 - r ) + ( d * r ) / ( 1 - r * r ) ; System . out . print ( ans ) ; } public static void main ( String [ ] args ) { double a = 0 , d = 1 , r = 0.5 ; sumOfInfiniteAGP ( a , d , r ) ; } }


"Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle | Java code to find the area of inscribed circle of equilateral triangle ; function to find the area of inscribed circle ; function to find the perimeter of inscribed circle ; Driver code"
How can the above be solved in Java?

import java . lang . * ; class GFG { static double PI = 3.14159265 ; public static double area_inscribed ( double a ) { return ( a * a * ( PI / 12 ) ) ; } public static double perm_inscribed ( double a ) { return ( PI * ( a / Math . sqrt ( 3 ) ) ) ; } public static void main ( String [ ] args ) { double a = 6.0 ; System . out . println ( " Area ▁ of ▁ inscribed ▁ circle ▁ is ▁ : " + area_inscribed ( a ) ) ; System . out . println ( " Perimeter of inscribed circle is : " + perm_inscribed ( a ) ) ; } }


"Program to calculate the area between two Concentric Circles | Java program to find area between the two given concentric circles ; Function to find area between the two given concentric circles ; Declare value of pi ; Calculate area of outer circle ; Calculate area of inner circle ; Difference in areas ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static double calculateArea ( int x , int y ) { double pi = 3.1415926536 ; double arx = pi * x * x ; double ary = pi * y * y ; return arx - ary ; } public static void main ( String [ ] args ) { int x = 2 ; int y = 1 ; System . out . println ( calculateArea ( x , y ) ) ; } }


"Program to calculate the area of Kite | Java implementation of the approach ; Function to return the area of kite ; Use above formula ; Driver code"
How can the above be solved in Java?

class GFG { static float areaOfKite ( int d1 , int d2 ) { float area = ( d1 * d2 ) / 2 ; return area ; } public static void main ( String [ ] args ) { int d1 = 4 , d2 = 6 ; System . out . println ( " Area ▁ of ▁ Kite ▁ = ▁ " + areaOfKite ( d1 , d2 ) ) ; } }


"Program to calculate the area of Kite | Java implementation of the approach ; Function to return the area of the kite ; convert angle degree to radians ; use above formula ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static double PI = ( 3.14159 / 180 ) ; static float areaOfKite ( int a , int b , double angle ) { angle = angle * PI ; double area = a * b * Math . sin ( angle ) ; return ( float ) area ; } public static void main ( String [ ] args ) { int a = 4 , b = 7 , angle = 78 ; System . out . println ( " Area ▁ of ▁ Kite ▁ = ▁ " + areaOfKite ( a , b , angle ) ) ; } }


"Program to calculate the number of odd days in given number of years | Java implementation of the approach ; Function to return the count of odd days ; Count of years divisible by 100 and 400 ; Every 4 th year is a leap year ; Every 100 th year is divisible by 4 but is not a leap year ; Every 400 th year is divisible by 100 but is a leap year ; Total number of extra days ; modulo ( 7 ) for final answer ; Driver code ; Number of days"
How can the above be solved in Java?

class GFG { static int oddDays ( int N ) { int hund1 = N / 100 ; int hund4 = N / 400 ; int leap = N >> 2 ; int ord = N - leap ; if ( hund1 > 0 ) { ord += hund1 ; leap -= hund1 ; } if ( hund4 > 0 ) { ord -= hund4 ; leap += hund4 ; } int days = ord + leap * 2 ; int odd = days % 7 ; return odd ; } public static void main ( String args [ ] ) { int N = 100 ; System . out . print ( oddDays ( N ) ) ; } }


"Program to calculate the value of sin ( x ) and cos ( x ) using Expansion | Java code for implementing cos function ; Function for calculation ; Converting degrees to radian ; maps the sum along the series ; holds the actual value of sin ( n ) ; Main function"
How can the above be solved in Java?

import static java . lang . Math . cos ; class GFG { static void cal_cos ( float n ) { float accuracy = ( float ) 0.0001 , x1 , denominator , cosx , cosval ; n = n * ( float ) ( 3.142 / 180.0 ) ; x1 = 1 ; cosx = x1 ; cosval = ( float ) 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 <= cosval - cosx ) ; System . out . println ( cosx ) ; } public static void main ( String [ ] args ) { float n = 30 ; cal_cos ( n ) ; } }


"Program to calculate value of nCr | Java program To calculate The Value Of nCr ; Returns factorial of n ; Driver code"
How can the above be solved in Java?

class GFG { static int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } public static void main ( String [ ] args ) { int n = 5 , r = 3 ; System . out . println ( nCr ( n , r ) ) ; } }


"Program to calculate volume of Ellipsoid | Java program to find the volume of Ellipsoid . ; Function to find the volume ; Driver Code"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; class GfG { public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) { float pi = ( float ) 3.14 ; return ( float ) 1.33 * pi * r1 * r2 * r3 ; } public static void main ( String args [ ] ) { float r1 = ( float ) 2.3 , r2 = ( float ) 3.4 , r3 = ( float ) 5.7 ; System . out . println ( " volume ▁ of ▁ ellipsoid ▁ is ▁ : ▁ " + volumeOfEllipsoid ( r1 , r2 , r3 ) ) ; } }


"Program to calculate volume of Octahedron | Java Program to calculate volume of Octahedron ; Driver Function ; utility Function"
How can the above be solved in Java?

import java . io . * ; class GFG { public static void main ( String [ ] args ) { double side = 3 ; System . out . print ( " Volume ▁ of ▁ octahedron ▁ = ▁ " ) ; System . out . println ( vol_of_octahedron ( side ) ) ; } static double vol_of_octahedron ( double side ) { return ( ( side * side * side ) * ( Math . sqrt ( 2 ) / 3 ) ) ; } }


"Program to check Involutory Matrix | Java Program to implement involutory matrix . ; Function for matrix multiplication . ; Function to check involutory matrix . ; multiply function call . ; Driver function . ; Function call . If function return true then if part will execute otherwise else part will execute ."
How can the above be solved in Java?

import java . io . * ; class GFG { static int N = 3 ; static void multiply ( int mat [ ] [ ] , int res [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { res [ i ] [ j ] = 0 ; for ( int k = 0 ; k < N ; k ++ ) res [ i ] [ j ] += mat [ i ] [ k ] * mat [ k ] [ j ] ; } } } static boolean InvolutoryMatrix ( int mat [ ] [ ] ) { int res [ ] [ ] = new int [ N ] [ N ] ; multiply ( mat , res ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i == j && res [ i ] [ j ] != 1 ) return false ; if ( i != j && res [ i ] [ j ] != 0 ) return false ; } } return true ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 0 , 0 } , { 0 , - 1 , 0 } , { 0 , 0 , - 1 } } ; if ( InvolutoryMatrix ( mat ) ) System . out . println ( " Involutory ▁ Matrix " ) ; else System . out . println ( " Not ▁ Involutory ▁ Matrix " ) ; } }


"Program to check Plus Perfect Number | java implementation to check if the number is plus perfect or not ; function to check plus perfect number ; calculating number of digits ; calculating plus perfect number ; checking whether number is plus perfect or not ; Driver program"
How can the above be solved in Java?

import java . io . * ; class GFG { static boolean checkplusperfect ( int x ) { int temp = x ; int n = 0 ; while ( x != 0 ) { x /= 10 ; n ++ ; } x = temp ; int sum = 0 ; while ( x != 0 ) { sum += Math . pow ( x % 10 , n ) ; x /= 10 ; } return ( sum == temp ) ; } public static void main ( String [ ] args ) { int x = 9474 ; if ( checkplusperfect ( x ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }


"Program to check Strength of Password | Java implementation fo the above approach ; Checking lower alphabet in string ; Strength of password ; Driver Code"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { public static void printStrongNess ( String input ) { int n = input . length ( ) ; boolean hasLower = false , hasUpper = false , hasDigit = false , specialChar = false ; Set < Character > set = new HashSet < Character > ( Arrays . asList ( ' ! ' , ' @ ' , ' # ' , ' $ ' , ' % ' , ' ^ ' , ' & ' , ' * ' , ' ( ' , ' ) ' , ' - ' , ' + ' ) ) ; for ( char i : input . toCharArray ( ) ) { if ( Character . isLowerCase ( i ) ) hasLower = true ; if ( Character . isUpperCase ( i ) ) hasUpper = true ; if ( Character . isDigit ( i ) ) hasDigit = true ; if ( set . contains ( i ) ) specialChar = true ; } System . out . print ( " Strength ▁ of ▁ password : - ▁ " ) ; if ( hasDigit && hasLower && hasUpper && specialChar && ( n >= 8 ) ) System . out . print ( " ▁ Strong " ) ; else if ( ( hasLower hasUpper specialChar ) && ( n >= 6 ) ) System . out . print ( " ▁ Moderate " ) ; else System . out . print ( " ▁ Weak " ) ; } public static void main ( String [ ] args ) { String input = " GeeksforGeeks ! @12" ; printStrongNess ( input ) ; } }


"Program to check diagonal matrix and scalar matrix | Program to check matrix is diagonal matrix or not . ; Function to check matrix is diagonal matrix or not . ; condition to check other elements except main diagonal are zero or not . ; Driver function"
How can the above be solved in Java?

import java . io . * ; class GFG { static int N = 4 ; static boolean isDiagonalMatrix ( int mat [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ; return true ; } public static void main ( String args [ ] ) { int mat [ ] [ ] = { { 4 , 0 , 0 , 0 } , { 0 , 7 , 0 , 0 } , { 0 , 0 , 5 , 0 } , { 0 , 0 , 0 , 1 } } ; if ( isDiagonalMatrix ( mat ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }


"Program to check diagonal matrix and scalar matrix | Program to check matrix is scalar matrix or not . ; Function to check matrix is scalar matrix or not . ; Check all elements except main diagonal are zero or not . ; Check all diagonal elements are same or not . ; Driver function ; Function call"
How can the above be solved in Java?

import java . io . * ; class GFG { static int N = 4 ; static boolean isScalarMatrix ( int mat [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ; for ( int i = 0 ; i < N - 1 ; i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ; return true ; } public static void main ( String args [ ] ) { int mat [ ] [ ] = { { 2 , 0 , 0 , 0 } , { 0 , 2 , 0 , 0 } , { 0 , 0 , 2 , 0 } , { 0 , 0 , 0 , 2 } } ; if ( isScalarMatrix ( mat ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }


"Program to check if N is a Centered Cubic Number | Java program to check if N is a centered cubic number ; Function to check if N is a centered cubic number ; Iterating from 1 ; Infinite loop ; Finding ith_term ; Checking if the number N is a centered cube number ; If ith_term > N then N is not a centered cube number ; Incrementing i ; Driver code ; Function call"
How can the above be solved in Java?

class GFG { static boolean isCenteredcube ( int N ) { int i = 1 ; while ( true ) { int ith_term = ( 2 * i + 1 ) * ( i * i + i + 1 ) ; if ( ith_term == N ) { return true ; } if ( ith_term > N ) { return false ; } i ++ ; } } public static void main ( String [ ] args ) { int N = 9 ; if ( isCenteredcube ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Centered Decagonal Number | Java implementation to check that a number is a centered decagonal number or not ; Function to check that the number is a centered decagonal number ; Condition to check if the number is a centered decagonal number ; Driver Code ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean isCentereddecagonal ( int N ) { double n = ( 5 + Math . sqrt ( 20 * N + 5 ) ) / 10 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int n = 11 ; if ( isCentereddecagonal ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Centered Octadecagonal number | Java implementation to check that a number is a centered octadecagonal number or not ; Function to check that the number is a centered octadecagonal number ; Implement the formula generated ; Condition to check if the number is a Centered Octadecagonal number ; Driver Code ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean isCenteredOctadecagonal ( int N ) { double n = ( 9 + Math . sqrt ( 36 * N + 45 ) ) / 18 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int n = 19 ; if ( isCenteredOctadecagonal ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Centered Pentagonal Number or not | Java program for the above approach ; Function to check if number N is a centered pentagonal number ; Condition to check if N is a centered pentagonal number ; Driver Code ; Given Number ; Function call"
How can the above be solved in Java?

import java . util . * ; class GFG { static boolean isCenteredpentagonal ( int N ) { float n = ( float ) ( ( 5 + Math . sqrt ( 40 * N - 15 ) ) / 10 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 6 ; if ( isCenteredpentagonal ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Centered Tridecagonal Number | Java program for the above approach ; Function to check if the number N is a centered tridecagonal number ; Condition to check if the N is a centered tridecagonal number ; Driver Code ; Given Number ; Function call"
How can the above be solved in Java?

class GFG { static boolean isCenteredtridecagonal ( int N ) { float n = ( float ) ( ( 13 + Math . sqrt ( 104 * N + 65 ) ) / 26 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 14 ; if ( isCenteredtridecagonal ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Centered heptagonal number | Java implementation to check that a number is a Centered heptagonal number or not ; Function to check that the number is a Centered heptagonal number ; Condition to check if the number is a Centered heptagonal number ; Driver Code ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean isCenteredheptagonal ( int N ) { double n = ( 7 + Math . sqrt ( 56 * N - 7 ) ) / 14 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int n = 8 ; if ( isCenteredheptagonal ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Centered nonadecagonal number | Java implementation to check that a number is a Centered nonadecagonal number or not ; Function to check that the number is a Centered nonadecagonal number ; Condition to check if the number is a Centered nonadecagonal number ; Driver Code ; Function call"
How can the above be solved in Java?

class GFG { static boolean isCenterednonadecagonal ( int N ) { float n = ( float ) ( ( 19 + Math . sqrt ( 152 * N + 209 ) ) / 38 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int n = 20 ; if ( isCenterednonadecagonal ( n ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Chiliagon Number | Java program for the above approach ; Function to check that if N is Chiliagon Number or not ; Condition to check if N is a Chiliagon Number ; Driver Code ; Given Number ; Function call"
How can the above be solved in Java?

class GFG { static boolean is_Chiliagon ( int N ) { float n = ( float ) ( 996 + Math . sqrt ( 7984 * N + 992016 ) ) / 1996 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String s [ ] ) { int N = 1000 ; if ( is_Chiliagon ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Concentric Hexagonal Number | Java program to check if N is a Concentric Hexagonal Number ; Function to check if the number is a Concentric hexagonal number ; Condition to check if the number is a Concentric hexagonal number ; Driver Code ; Function call"
How can the above be solved in Java?

class GFG { static boolean isConcentrichexagonal ( int N ) { float n = ( float ) Math . sqrt ( ( 2 * N ) / 3 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 6 ; if ( isConcentrichexagonal ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Decagonal Number | Java program for the above approach ; Function to check if N is a decagonal number ; Condition to check if the number is a decagonal number ; Driver code ; Given number ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean isdecagonal ( int N ) { double n = ( 3 + Math . sqrt ( 16 * N + 9 ) ) / 8 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 10 ; if ( isdecagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Dodecagonal Number | Java program for the above approach ; Function to check if number N is a dodecagonal number or not ; Condition to check if the N is a dodecagonal number ; Driver Code ; Given Number ; Function call"
How can the above be solved in Java?

import java . util . * ; class GFG { static boolean isdodecagonal ( int N ) { float n = ( float ) ( ( 4 + Math . sqrt ( 20 * N + 16 ) ) / 10 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 12 ; if ( isdodecagonal ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Enneadecagonal Number | Java program for the above approach ; Function to check if number N is a enneadecagonal number ; Condition to check if N is a enneadecagonal number ; Driver Code ; Given Number ; Function call"
How can the above be solved in Java?

class GFG { static boolean isenneadecagonal ( int N ) { float n = ( float ) ( 15 + Math . sqrt ( 136 * N + 225 ) ) / 34 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 19 ; if ( isenneadecagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Hendecagonal Number | Java program for the above approach ; Function to check if N is a hendecagonal number ; Condition to check if the number is a hendecagonal number ; Driver code ; Given number ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean ishendecagonal ( int N ) { double n = ( 7 + Math . sqrt ( 72 * N + 49 ) ) / 18 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 11 ; if ( ishendecagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Heptagonal Number | Java program for the above approach ; Function to check if N is a heptagonal number ; Condition to check if the number is a heptagonal number ; Driver code ; Given Number ; Function call"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { public static boolean isheptagonal ( int N ) { double n = ( 3 + Math . sqrt ( 40 * N + 9 ) ) / 10 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 7 ; if ( isheptagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Hexadecagonal Number | Java program for the above approach ; Function to check if N is a hexadecagonal number ; Condition to check if the number is a hexadecagonal number ; Driver code ; Given number ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean ishexadecagonal ( int N ) { double n = ( 12 + Math . sqrt ( 112 * N + 144 ) ) / 28 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 16 ; if ( ishexadecagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Hexagonal Number or not | Java program to check if N is a hexagonal number ; Function to check if number is hexagonal ; Calculate the value for n ; Check if n - floor ( n ) is equal to 0 ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static boolean isHexagonal ( int N ) { float val = 8 * N + 1 ; float x = 1 + ( float ) Math . sqrt ( val ) ; float n = ( x ) / 4 ; if ( ( n - ( int ) n ) == 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { int N = 14 ; if ( isHexagonal ( N ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }


"Program to check if N is a Icosihenagonal number | Java implementation to check that a number is icosihenagonal number or not ; Function to check that the number is a icosihenagonal number ; Condition to check if the number is a icosihenagonal number ; Driver Code ; Function call"
How can the above be solved in Java?

class GFG { static boolean isicosihenagonal ( int N ) { float n = ( float ) ( ( 17 + Math . sqrt ( 152 * N + 289 ) ) / 38 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int i = 21 ; if ( isicosihenagonal ( i ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Icositetragonal number | Java implementation to check that a number is icositetragonal number or not ; Function to check that the number is a icositetragonal number ; Condition to check if the number is a icositetragonal number ; Driver Code ; Function call"
How can the above be solved in Java?

class GFG { static boolean isicositetragonal ( int N ) { float n = ( float ) ( ( 10 + Math . sqrt ( 44 * N + 100 ) ) / 22 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int i = 24 ; if ( isicositetragonal ( i ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Icositrigonal number | Java implementation to check that a number is a icositrigonal number or not ; Function to check that the number is a icositrigonal number ; Condition to check if the number is a icositrigonal number ; Driver Code ; Function call"
How can the above be solved in Java?

import java . util . * ; class GFG { static boolean isicositrigonal ( int N ) { float n = ( float ) ( 19 + Math . sqrt ( 168 * N + 361 ) ) / 42 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String args [ ] ) { int i = 23 ; if ( isicositrigonal ( i ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a Myriagon Number | Java program for the above approach ; Function to check if N is a myriagon number ; Condition to check if the number is a myriagon number ; Driver Code ; Given Number ; Function call"
How can the above be solved in Java?

import java . io . * ; class GFG { static boolean isMyriagon ( int N ) { double n = ( 9996 + Math . sqrt ( 79984 * N + 99920016 ) ) / 19996 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 10000 ; if ( isMyriagon ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Nonagonal Number | Java program for the above approach ; Function to check if N is a nonagonal number ; Condition to check if the number is a nonagonal number ; Driver code ; Given number ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean isnonagonal ( int N ) { double n = ( 5 + Math . sqrt ( 56 * N + 25 ) ) / 14 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 9 ; if ( isnonagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Octadecagon number | Java program for the above approach ; Function to check if N is a octadecagon Number ; Condition to check if the number is a octadecagon number ; Driver Code ; Given Number ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean isOctadecagon ( int N ) { double n = ( 14 + Math . sqrt ( 128 * N + 196 ) ) / 32 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 18 ; if ( isOctadecagon ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Octagonal Number | Java program for the above approach ; Function to check if N is a octagonal number ; Condition to check if the number is a octagonal number ; Driver code ; Given Number ; Function call"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { public static boolean isoctagonal ( int N ) { double n = ( 2 + Math . sqrt ( 12 * N + 4 ) ) / 6 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 8 ; if ( isoctagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Pentadecagonal Number | Java program for the above approach ; Function to check if N is a pentadecagon number ; Condition to check if the number is a pentadecagon number ; Driver code ; Given Number ; Function call"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { public static boolean isPentadecagon ( int N ) { double n = ( 11 + Math . sqrt ( 104 * N + 121 ) ) / 26 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 15 ; if ( isPentadecagon ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Pentagonal Number | Java program to check pentagonal numbers . ; Function to determine if N is pentagonal or not . ; Substitute values of i in the formula . ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static Boolean isPentagonal ( int N ) { int i = 1 , M ; do { M = ( 3 * i * i - i ) / 2 ; i += 1 ; } while ( M < N ) ; return ( M == N ) ; } public static void main ( String [ ] args ) { int N = 12 ; if ( isPentagonal ( N ) ) System . out . println ( N + " ▁ is ▁ pentagonal ▁ " ) ; else System . out . println ( N + " ▁ is ▁ not ▁ pentagonal " ) ; } }


"Program to check if N is a Star Number | Java implementation to check that a number is a star number or not ; Function to check that the number is a star number ; Condition to check if the number is a star number ; Driver code ; Function call"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { static boolean isStar ( int N ) { double n = ( 6 + Math . sqrt ( 24 * N + 12 ) ) / 6 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int i = 13 ; if ( isStar ( i ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Tetradecagonal Number | Java program for the above approach ; Function to check if N is a tetradecagonal number ; Condition to check if the number is a tetradecagonal number ; Driver Code ; Given number ; Function call"
How can the above be solved in Java?

import java . lang . Math ; class GFG { public static boolean istetradecagonal ( int N ) { double n = ( 10 + Math . sqrt ( 96 * N + 100 ) ) / 24 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 11 ; if ( istetradecagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if N is a Tridecagonal Number or not | Java implementation to check that a number is a tridecagon number or not ; Function to check that the number is a tridecagon number ; Condition to check if the number is a tridecagon number ; Driver Code ; Function call"
How can the above be solved in Java?

class GFG { static boolean isTridecagon ( int N ) { float n = ( float ) ( ( 9 + Math . sqrt ( 88 * N + 81 ) ) / 22 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int i = 13 ; if ( isTridecagon ( i ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if N is a triacontagonal number | Java program to check whether a number is an triacontagonal number or not ; Function to check whether a number is an triacontagonal number or not ; Condition to check whether a number is an triacontagonal number or not ; Driver code ; Given number ; Function call"
How can the above be solved in Java?

class GFG { static boolean istriacontagonal ( int N ) { float n = ( float ) ( ( 26 + Math . sqrt ( 224 * N + 676 ) ) / 56 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 30 ; if ( istriacontagonal ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }


"Program to check if a number can be expressed as an even power of 2 or not | Java program for the above approach ; Function to check if N can be expressed as an even power of 2 ; Iterate till x is N ; if x is even then return true ; Increment x ; If N is not a power of 2 ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class GFG { static boolean checkEvenPower ( int n ) { int x = 0 ; while ( x < n ) { int value = ( int ) Math . pow ( 2 , x ) ; if ( value == n ) { if ( x % 2 == 0 ) return true ; else return false ; } x ++ ; } return false ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( ( checkEvenPower ( N ) ? " Yes " : " No " ) ) ; } }


"Program to check if a number can be expressed as an even power of 2 or not | Java program for the above approach ; Function to check if N can be expressed as an even power of 2 or not ; If N is not a power of 2 ; Bitwise AND operation ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class GFG { static boolean checkEvenPower ( long N ) { if ( ( N & ( N - 1 ) ) != 0 ) return false ; N = N & 0x55555555 ; return ( N > 0 ) ; } public static void main ( String [ ] args ) { long N = 4 ; System . out . println ( checkEvenPower ( N ) ? 1 : 0 ) ; } }


"Program to check if a number can be expressed as an even power of 2 or not | Java program for the above approach ; Function to check if N can be expressed as an even power of 2 or not ; Iterate until low > high ; Calculate mid ; If 2 ^ mid is equal to n ; If mid is odd ; Update the value of low ; Update the value of high ; Otherwise ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static String checkEvenPower ( int n ) { int low = 0 , high = n ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; int value = ( int ) Math . pow ( 2 , mid ) ; if ( value == n ) { if ( mid % 2 == 1 ) return " No " ; else return " Yes " ; } else if ( value < n ) low = mid + 1 ; else high = mid - 1 ; } return " No " ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( checkEvenPower ( N ) ) ; } }


"Program to check if a number is divisible by any of its digits | JAva implementation of above approach ; Converting integer to string ; Traversing the string ; find the actual digit ; If the number is divisible by digits then return yes ; If no digits are dividing the number then return no ; Driver Code ; passing this number to get result function"
How can the above be solved in Java?

import java . io . * ; class GFG { static String getResult ( int n ) { String st = Integer . toString ( n ) ; for ( int i = 0 ; i < st . length ( ) ; i ++ ) { int d = st . charAt ( i ) - 48 ; if ( n % d == 0 ) { return " Yes " ; } } return " No " ; } public static void main ( String [ ] args ) { int n = 9876543 ; System . out . println ( getResult ( n ) ) ; } }


"Program to check if a number is divisible by any of its digits | Java implementation of above approach ; Function to check if given number is divisible by any of its digits ; check if any of digit divides n ; check if K divides N ; Driver Code"
How can the above be solved in Java?

class GFG { static String isDivisible ( int n ) { int temp = n ; while ( n > 0 ) { int k = n % 10 ; if ( temp % k == 0 ) { return " YES " ; } n /= 10 ; } return " NO " ; } public static void main ( String [ ] args ) { int n = 9876543 ; System . out . println ( isDivisible ( n ) ) ; } }


"Program to check if a number is divisible by sum of its digits | Java implementation of above approach ; Converting integer to String ; Initialising sum to 0 ; Traversing through the String ; Converting character to int ; Comparing number and sum ; Driver Code ; Passing this number to get result function"
How can the above be solved in Java?

class GFG { static String getResult ( int n ) { String st = String . valueOf ( n ) ; int sum = 0 ; for ( char i : st . toCharArray ( ) ) { sum = sum + ( int ) i ; } if ( n % sum == 0 ) return " Yes " ; else return " No " ; } public static void main ( String [ ] args ) { int n = 123 ; System . out . println ( getResult ( n ) ) ; } }


"Program to check if a number is divisible by sum of its digits | Java implementation of above approach ; Function to check if the given number is divisible by sum of its digits ; Find sum of digits ; check if sum of digits divides n ; Driver Code"
How can the above be solved in Java?

class GFG { static String isDivisible ( long n ) { long temp = n ; int sum = 0 ; while ( n != 0 ) { int k = ( int ) n % 10 ; sum += k ; n /= 10 ; } if ( temp % sum == 0 ) return " YES " ; return " NO " ; } public static void main ( String [ ] args ) { long n = 123 ; System . out . println ( isDivisible ( n ) ) ; } }


"Program to check if all characters have even frequency | Java implementation of the above approach ; creating a frequency array ; Finding length of s ; counting frequency of all characters ; checking if any odd frequency is there or not ; Driver Code"
How can the above be solved in Java?

class GFG { static boolean check ( String s ) { int [ ] freq = new int [ 26 ] ; int n = s . length ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { freq [ ( s . charAt ( i ) ) - 97 ] += 1 ; } for ( int i = 0 ; i < freq . length ; i ++ ) { if ( freq [ i ] % 2 == 1 ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String s = " abaccaba " ; if ( check ( s ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }


"Program to check if tank will overflow , underflow or filled in given time | Java program to check if Tank will overflow or not in given time ; function to calculate the volume of tank ; function to print overflow / filled / underflow accordingly ; driver code ; radius of the tank ; height of the tank ; rate of flow of water ; time given ; calculate the required time ; printing the result"
How can the above be solved in Java?

class Number { public static float volume ( int radius , int height ) { return ( ( 22 / 7 ) * radius * radius * height ) ; } public static void check_and_print ( double required_time , double given_time ) { if ( required_time < given_time ) System . out . print ( " Overflow " ) ; else if ( required_time > given_time ) System . out . print ( " Underflow " ) ; else System . out . print ( " Filled " ) ; } public static void main ( String [ ] args ) { int radius = 5 , height = 10 , rate_of_flow = 10 ; double given_time = 70.0 ; double required_time = volume ( radius , height ) / rate_of_flow ; check_and_print ( required_time , given_time ) ; } }


"Program to check if the points are parallel to X axis or Y axis | Java program to illustrate . . To check for parallel To X and Y Axis ; To check for parallel line ; checking for parallel to X and Y axis condition ; To display the output ; Driver 's Code"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { static void parallel ( int a [ ] [ ] ) { boolean x = true , y = true ; for ( int i = 0 ; i < a . length - 1 ; i ++ ) { if ( a [ i ] [ 0 ] != a [ i + 1 ] [ 0 ] ) x = false ; if ( a [ i ] [ 1 ] != a [ i + 1 ] [ 1 ] ) y = false ; } if ( x ) System . out . println ( " Parallel ▁ to ▁ Y ▁ Axis " ) ; else if ( y ) System . out . println ( " Parallel ▁ to ▁ X ▁ Axis " ) ; else System . out . println ( " Not ▁ parallel ▁ to ▁ X " + " ▁ and ▁ Y ▁ axis " ) ; } public static void main ( String [ ] args ) { int a [ ] [ ] = { { 1 , 2 } , { 1 , 4 } , { 1 , 6 } , { 1 , 0 } } ; parallel ( a ) ; } }


"Program to check if three points are collinear | Slope based solution to check if three points are collinear . ; function to check if point collinear or not ; Driver Code"
How can the above be solved in Java?

import java . io . * ; class GFG { static void cool_line ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { if ( ( y3 - y2 ) * ( x2 - x1 ) == ( y2 - y1 ) * ( x3 - x2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int a1 = 1 , a2 = 1 , a3 = 0 , b1 = 1 , b2 = 6 , b3 = 9 ; cool_line ( a1 , b1 , a2 , b2 , a3 , b3 ) ; } }


"Program to check if water tank overflows when n solid balls are dipped in the water tank | JAVA Code for Program to check if water tank overflows ; function to find if tak will overflow or not ; cylinder capacity ; volume of water in tank ; volume of n balls ; total volume of water and n dipped balls ; condition to check if tank is in overflow state or not ; Driver program to test above function ; giving dimensions ; calling function"
How can the above be solved in Java?

import java . util . * ; class GFG { static void overflow ( int H , int r , int h , int N , int R ) { double tank_cap = 3.14 * r * r * H ; double water_vol = 3.14 * r * r * h ; double balls_vol = N * ( 4 / 3 ) * 3.14 * R * R * R ; double vol = water_vol + balls_vol ; if ( vol > tank_cap ) { System . out . println ( " Overflow " ) ; } else { System . out . println ( " Not ▁ in ▁ overflow ▁ state " ) ; } } public static void main ( String [ ] args ) { int H = 10 , r = 5 , h = 5 , N = 2 , R = 2 ; overflow ( H , r , h , N , R ) ; } }


"Program to check similarity of given two triangles | Java program to check similarity between two triangles . ; Function for AAA similarity ; Check for AAA ; Function for SAS similarity ; angle b / w two smallest sides is largest . ; since we take angle b / w the sides . ; Function for SSS similarity ; Check for SSS ; Driver Code ; function call for AAA similarity ; function call for SSS similarity ; function call for SAS similarity ; Check if triangles are similar or not"
How can the above be solved in Java?

import java . util . * ; class GFG1 { static int simi_aaa ( int a1 [ ] , int a2 [ ] ) { Arrays . sort ( a1 ) ; Arrays . sort ( a2 ) ; if ( a1 [ 0 ] == a2 [ 0 ] && a1 [ 1 ] == a2 [ 1 ] && a1 [ 2 ] == a2 [ 2 ] ) return 1 ; else return 0 ; } static int simi_sas ( int s1 [ ] , int s2 [ ] , int a1 [ ] , int a2 [ ] ) { Arrays . sort ( a1 ) ; Arrays . sort ( a2 ) ; Arrays . sort ( s1 ) ; Arrays . sort ( s2 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] ) { if ( a1 [ 2 ] == a2 [ 2 ] ) return 1 ; } if ( s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] ) { if ( a1 [ 0 ] == a2 [ 0 ] ) return 1 ; } if ( s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) { if ( a1 [ 1 ] == a2 [ 1 ] ) return 1 ; } return 0 ; } static int simi_sss ( int s1 [ ] , int s2 [ ] ) { Arrays . sort ( s1 ) ; Arrays . sort ( s2 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] && s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] && s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) return 1 ; return 0 ; } public static void main ( String args [ ] ) { int s1 [ ] = { 2 , 3 , 3 } ; int s2 [ ] = { 4 , 6 , 6 } ; int a1 [ ] = { 80 , 60 , 40 } ; int a2 [ ] = { 40 , 60 , 80 } ; int aaa = simi_aaa ( a1 , a2 ) ; int sss = simi_sss ( s1 , s2 ) ; int sas = simi_sas ( s1 , s2 , a1 , a2 ) ; if ( aaa == 1 sss == 1 sas == 1 ) { System . out . print ( " Triangles ▁ are ▁ " + " similar ▁ by ▁ " ) ; if ( aaa == 1 ) System . out . print ( " AAA ▁ " ) ; if ( sss == 1 ) System . out . print ( " SSS ▁ " ) ; if ( sas == 1 ) System . out . print ( " SAS . " ) ; } else System . out . println ( " Triangles ▁ are ▁ " + " not ▁ similar " ) ; } }


"Program to check whether 4 points in a 3 | Java program to check if 4 points in a 3 - D plane are Coplanar ; Function to find equation of plane . ; checking if the 4 th point satisfies the above equation ; Driver Code ; function calling"
How can the above be solved in Java?

public class GFG { static void equation_plane ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , int x3 , int y3 , int z3 , int x , int y , int z ) { 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 ) ; if ( a * x + b * y + c * z + d == 0 ) System . out . println ( " Coplanar " ) ; else System . out . println ( " Not ▁ Coplanar " ) ; } public static void main ( String [ ] args ) { int x1 = 3 ; int y1 = 2 ; int z1 = - 5 ; int x2 = - 1 ; int y2 = 4 ; int z2 = - 3 ; int x3 = - 3 ; int y3 = 8 ; int z3 = - 5 ; int x4 = - 3 ; int y4 = 2 ; int z4 = 1 ; equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 , x4 , y4 , z4 ) ; } }


"Program to check whether a number is Proth number or not | Java program to check for Proth number ; Utility function to check power of two ; Function to check if the Given number is Proth number or not ; check if k divides n or not ; Check if n / k is power of 2 or not ; update k to next odd number ; If we reach here means there exists no value of K Such that k is odd number and n / k is a power of 2 greater than k ; Driver code ; Get n ; Check n for Proth Number"
How can the above be solved in Java?

class GFG { static boolean isPowerOfTwo ( int n ) { return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) ; } static boolean isProthNumber ( int n ) { int k = 1 ; while ( k < ( n / k ) ) { if ( n % k == 0 ) { if ( isPowerOfTwo ( n / k ) ) return true ; } k = k + 2 ; } return false ; } public static void main ( String [ ] args ) { int n = 25 ; if ( isProthNumber ( n - 1 ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }


"Program to clear K | Java program to clear K - th bit of a number N ; Function to clear the kth bit of n ; Driver code"
How can the above be solved in Java?

class GFG { static int clearBit ( int n , int k ) { return ( n & ( ~ ( 1 << ( k - 1 ) ) ) ) ; } public static void main ( String [ ] args ) { int n = 5 , k = 1 ; System . out . println ( clearBit ( n , k ) ) ; } }


"Program to compare m ^ n and n ^ m | Java program to compare which is greater m ^ n or n ^ m ; function to compare m ^ n and n ^ m ; m ^ n ; n ^ m ; Driver Code ; function call to compare m ^ n and n ^ m"
How can the above be solved in Java?

import java . io . * ; class GFG { static void check ( long m , long n ) { double RHS = m * ( double ) Math . log ( n ) ; double LHS = n * ( double ) Math . log ( m ) ; if ( LHS > RHS ) System . out . print ( " m ^ n ▁ > ▁ n ^ m " ) ; else if ( LHS < RHS ) System . out . print ( " m ^ n ▁ < ▁ n ^ m " ) ; else System . out . print ( " m ^ n ▁ = ▁ n ^ m " ) ; } static public void main ( String [ ] args ) { long m = 987654321 , n = 123456987 ; check ( m , n ) ; } }


"Program to compare two fractions | Java program to find max between two Rational numbers ; Constructor ; Get max of the two fractions ; Declare nume1 and nume2 for get the value of first numerator and second numerator ; Compute ad - bc ; Driver function"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class Fraction { int num , den ; Fraction ( int n , int d ) { num = n ; den = d ; } static Fraction maxFraction ( Fraction first , Fraction sec ) { int a = first . num ; int b = first . den ; int c = sec . num ; int d = sec . den ; int Y = a * d - b * c ; return ( Y > 0 ) ? first : sec ; } public static void main ( String [ ] args ) { Fraction first = new Fraction ( 3 , 2 ) ; Fraction sec = new Fraction ( 3 , 4 ) ; Fraction res = maxFraction ( first , sec ) ; System . out . println ( res . num + " / " + res . den ) ; } }


"Program to compute division upto n decimal places | Java program to compute division upto n decimal places . ; Base cases ; Since n <= 0 , don 't compute after  the decimal ; Handling negative numbers ; Integral division ; Now one by print digits after dot using school division method . ; Driver Program"
How can the above be solved in Java?

import java . util . * ; class Eulerian { public static void precisionCompute ( int x , int y , int n ) { if ( y == 0 ) { System . out . print ( " Infinite " ) ; return ; } if ( x == 0 ) { System . out . print ( "0" ) ; return ; } if ( n <= 0 ) { System . out . print ( x / y ) ; return ; } if ( ( ( x > 0 ) && ( y < 0 ) ) || ( ( x < 0 ) && ( y > 0 ) ) ) { System . out . print ( " - " ) ; x = x > 0 ? x : - x ; y = y > 0 ? y : - y ; } int d = x / y ; for ( int i = 0 ; i <= n ; i ++ ) { System . out . print ( d ) ; x = x - ( y * d ) ; if ( x == 0 ) break ; x = x * 10 ; d = x / y ; if ( i == 0 ) System . out . print ( " . " ) ; } } public static void main ( String [ ] args ) { int x = 22 , y = 7 , n = 15 ; precisionCompute ( x , y , n ) ; } }


"Program to compute log a to any base b ( logb a ) | Java program to find log ( a ) on any base b ; Driver code"
How can the above be solved in Java?

class GFG { static int log_a_to_base_b ( int a , int b ) { return ( int ) ( Math . log ( a ) / Math . log ( b ) ) ; } public static void main ( String [ ] args ) { int a = 3 ; int b = 2 ; System . out . println ( log_a_to_base_b ( a , b ) ) ; a = 256 ; b = 4 ; System . out . println ( log_a_to_base_b ( a , b ) ) ; } }


"Program to compute log a to any base b ( logb a ) | Java program to find log ( a ) on any base b using Recursion ; Recursive function to compute log a to the base b ; Driver code"
How can the above be solved in Java?

class GFG { static int log_a_to_base_b ( int a , int b ) { int rslt = ( a > b - 1 ) ? 1 + log_a_to_base_b ( a / b , b ) : 0 ; return rslt ; } public static void main ( String [ ] args ) { int a = 3 ; int b = 2 ; System . out . println ( log_a_to_base_b ( a , b ) ) ; a = 256 ; b = 4 ; System . out . println ( log_a_to_base_b ( a , b ) ) ; } }


"Program to construct DFA accepting odd number of 0 s and odd number of 1 s | Java program for the above approach ; Function to check whether the given string is accepted by DFA or not ; Stores initial state of DFA ; Stores final state of DFA ; Stores previous state of DFA ; Iterate through the string ; Checking for all combinations ; Update the previous_state ; If final state is reached ; Otherwise ; Driver Code ; Given string ; Function Call"
How can the above be solved in Java?

import java . util . * ; class GFG { static void checkValidDFA ( String s ) { int initial_state = 0 ; int final_state = 0 ; int previous_state = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ( s . charAt ( i ) == '0' && previous_state == 0 ) || ( s . charAt ( i ) == '1' && previous_state == 3 ) ) { final_state = 1 ; } else if ( ( s . charAt ( i ) == '0' && previous_state == 3 ) || ( s . charAt ( i ) == '1' && previous_state == 0 ) ) { final_state = 2 ; } else if ( ( s . charAt ( i ) == '0' && previous_state == 1 ) || ( s . charAt ( i ) == '1' && previous_state == 2 ) ) { final_state = 0 ; } else if ( ( s . charAt ( i ) == '0' && previous_state == 2 ) || ( s . charAt ( i ) == '1' && previous_state == 1 ) ) { final_state = 3 ; } previous_state = final_state ; } if ( final_state == 3 ) { System . out . println ( " Accepted " ) ; } else { System . out . println ( " Not ▁ Accepted " ) ; } } public static void main ( String args [ ] ) { String s = "010011" ; checkValidDFA ( s ) ; } }


"Program to construct a DFA to check if a given integer is unsigned or not | Java program for the above approach ; Function to construct DFA as per the given conditions ; If at state 0 and a digit has occurred then set it to state 1 ; Similarly for all other states ; Function to build and connect the DFA states ; Connect all the states to the dead state ; Function call to make DFA as per the given conditions ; Function call to check whether an integer in the form of string is unsigned integer or not ; Build the DFA ; Stores the current state ; Traverse the string ; If at a certain state a digit occurs then change the current state according to the DFA ; Or + / - sign ; Or decimal occurred ; Or any other character ; Or e / E or exponent sign ; State 1 , 4 , 8 will give the final answer ; Driver Code"
How can the above be solved in Java?

import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static String digits = "0123456789" , sign = " + - " ; static String dot = " . " , ex = " eE " ; static int dfa [ ] [ ] = new int [ 11 ] [ 5 ] ; static void makeDFA ( ) { dfa [ 0 ] [ 0 ] = 1 ; dfa [ 1 ] [ 0 ] = 1 ; dfa [ 1 ] [ 2 ] = 3 ; dfa [ 1 ] [ 3 ] = 2 ; dfa [ 1 ] [ 4 ] = 6 ; dfa [ 3 ] [ 0 ] = 4 ; dfa [ 4 ] [ 0 ] = 4 ; dfa [ 4 ] [ 3 ] = 5 ; dfa [ 4 ] [ 4 ] = 6 ; dfa [ 6 ] [ 0 ] = 8 ; dfa [ 6 ] [ 1 ] = 7 ; dfa [ 7 ] [ 0 ] = 8 ; dfa [ 8 ] [ 0 ] = 8 ; dfa [ 8 ] [ 3 ] = 9 ; } static void buildDFA ( ) { for ( int i = 0 ; i < 11 ; i ++ ) for ( int j = 0 ; j < 5 ; j ++ ) dfa [ i ] [ j ] = 10 ; makeDFA ( ) ; } static void checkDFA ( String s ) { buildDFA ( ) ; int currentstate = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( digits . indexOf ( s . charAt ( i ) ) != - 1 ) currentstate = dfa [ currentstate ] [ 0 ] ; else if ( sign . indexOf ( s . charAt ( i ) ) != - 1 ) currentstate = dfa [ currentstate ] [ 1 ] ; else if ( dot . indexOf ( s . charAt ( i ) ) != - 1 ) currentstate = dfa [ currentstate ] [ 2 ] ; else if ( ex . indexOf ( s . charAt ( i ) ) != - 1 ) currentstate = dfa [ currentstate ] [ 4 ] ; else currentstate = dfa [ currentstate ] [ 3 ] ; } if ( currentstate == 1 currentstate == 4 currentstate == 8 ) { System . out . println ( " Unsigned ▁ integer " ) ; } else { System . out . println ( " Not ▁ an ▁ unsigned ▁ integer " ) ; } } public static void main ( String [ ] args ) { String S = "1729" ; checkDFA ( S ) ; } }


"Program to construct a DFA which accepts the language L = { aN | N â ‰¥ 1 } | Java program for the above approach ; Function to check whether the String S satisfy the given DFA or not ; Stores the count of characters ; Iterate over the range [ 0 , N ] ; Count and check every element for ' a ' ; If String matches with DFA ; If not matches ; Driver Code ; Function Call"
How can the above be solved in Java?

class GFG { static void isAcceptedDFA ( String s , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' a ' ) count ++ ; } if ( count == N && count != 0 ) { System . out . print ( " Accepted " ) ; } else { System . out . print ( " Not ▁ Accepted " ) ; } } public static void main ( String [ ] args ) { String S = " aaaaa " ; isAcceptedDFA ( S , S . length ( ) ) ; } }


"Program to convert Degree to Radian | Java program to convert degree to radian ; Function for conversion ; Driver code"
How can the above be solved in Java?

import java . io . * ; import java . util . * ; class GFG { static double Convert ( double degree ) { double pi = 3.14159265359 ; return ( degree * ( pi / 180 ) ) ; } public static void main ( String [ ] args ) { double degree = 30 ; double radian = Convert ( degree ) ; System . out . printf ( " % .6f " , radian ) ; } }


"Program to convert Hexa | Java implementation to convert the given HexaDecimal number to its equivalent BCD . ; Function to convert HexaDecimal to its BCD ; Iterating through the digits ; check whether s [ i ] is a character or a integer between 0 to 9 and compute its equivalent BCD ; Driver Code ; Function Call"
How can the above be solved in Java?

public class Main { public static void HexaDecimaltoBCD ( String s ) { int len = s . length ( ) , check = 0 ; int num = 0 , sum = 0 , mul = 1 ; for ( int i = 0 ; i <= len - 1 ; i ++ ) { if ( s . charAt ( i ) >= 47 && s . charAt ( i ) <= 52 ) { String result = Integer . toBinaryString ( ( int ) s . charAt ( i ) ) ; System . out . print ( result . substring ( result . length ( ) - 4 ) + " ▁ " ) ; } else { String result = Integer . toBinaryString ( ( int ) s . charAt ( i ) - 55 ) ; System . out . print ( result . substring ( result . length ( ) - 4 ) + " ▁ " ) ; } } } public static void main ( String [ ] args ) { String s = "11F " ; HexaDecimaltoBCD ( s ) ; } }


"Program to convert KiloBytes to Bytes and Bits | Java implementation of above program ; Function to calculates the bits ; calculates Bits 1 kilobytes ( s ) = 8192 bits ; Function to calculates the bytes ; calculates Bytes 1 KB = 1024 bytes ; Driver code"
How can the above be solved in Java?

import java . util . * ; import java . lang . * ; import java . io . * ; import java . math . BigInteger ; class GFG { static BigInteger Bits ( int kilobytes ) { BigInteger Bits = new BigInteger ( "0" ) ; BigInteger kilo = BigInteger . valueOf ( kilobytes ) ; Bits = kilo . multiply ( BigInteger . valueOf ( 8192 ) ) ; return Bits ; } static BigInteger Bytes ( int kilobytes ) { BigInteger Bytes = new BigInteger ( "0" ) ; BigInteger kilo = BigInteger . valueOf ( kilobytes ) ; Bytes = kilo . multiply ( BigInteger . valueOf ( 1024 ) ) ; return Bytes ; } public static void main ( String args [ ] ) { int kilobytes = 1 ; System . out . print ( kilobytes + " ▁ Kilobytes ▁ = ▁ " + Bytes ( kilobytes ) + " ▁ Bytes ▁ and ▁ " + Bits ( kilobytes ) + " ▁ Bits . " ) ; } }


"Program to convert Number in characters | Java program to convert number in characters ; To calculate the reverse of the number ; The remainder will give the last digit of the number ; Extract the first digit of the reversed number ; Match it with switch case ; Divide the number by 10 to get the next number ; Driver code"
How can the above be solved in Java?

class GFG { static void NumbertoCharacter ( int n ) { int rev = 0 , r = 0 ; while ( n > 0 ) { r = n % 10 ; rev = rev * 10 + r ; n = n / 10 ; } while ( rev > 0 ) { r = rev % 10 ; switch ( r ) { case 1 : System . out . print ( " one ▁ " ) ; break ; case 2 : System . out . print ( " two ▁ " ) ; break ; case 3 : System . out . print ( " three ▁ " ) ; break ; case 4 : System . out . print ( " four ▁ " ) ; break ; case 5 : System . out . print ( " five ▁ " ) ; break ; case 6 : System . out . print ( " six ▁ " ) ; break ; case 7 : System . out . print ( " seven ▁ " ) ; break ; case 8 : System . out . print ( " eight ▁ " ) ; break ; case 9 : System . out . print ( " nine ▁ " ) ; break ; case 0 : System . out . print ( " zero ▁ " ) ; break ; default : System . out . print ( " UnValid ▁ " ) ; break ; } rev = rev / 10 ; } } public static void main ( String [ ] args ) { int n = 12345 ; NumbertoCharacter ( n ) ; } }


"Program to convert a Binary Number to Hexa | Java code to convert BCD to its HexaDecimal number ( base 16 ) . Including Header Files ; Function to convert BCD to HexaDecimal ; Iterating through the bits backwards ; Computing the HexaDecimal Number formed so far and storing it in a vector . ; Reinitializing all variables for next group . ; Printing the Hexadecimal number formed so far . ; Driver Code ; Function Call"
How can the above be solved in Java?

import java . util . * ; class GFG { static void bcdToHexaDecimal ( char [ ] s ) { int len = s . length , check = 0 ; int num = 0 , sum = 0 , mul = 1 ; Vector < Character > ans = new Vector < Character > ( ) ; for ( int i = len - 1 ; i >= 0 ; i -- ) { sum += ( s [ i ] - '0' ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum <= 9 ) ans . add ( ( char ) ( sum + '0' ) ) ; else ans . add ( ( char ) ( sum + 55 ) ) ; check = 0 ; sum = 0 ; mul = 1 ; } } len = ans . size ( ) ; for ( int i = len - 1 ; i >= 0 ; i -- ) System . out . print ( ans . get ( i ) ) ; } public static void main ( String [ ] args ) { String s = "100000101111" ; bcdToHexaDecimal ( s . toCharArray ( ) ) ; } }


"Program to convert a given number to words | Java program to print a given number in words . The program handles numbers from 0 to 9999 ; A function that prints given number in words ; Get number of digits in given number ; Base cases ; The first string is not used , it is to make array indexing simple ; The first string is not used , it is to make array indexing simple ; The first two string are not used , they are to * make array indexing simple ; Used for debugging purpose only ; For single digit number ; Iterate while num is not ' \0' ; Code path for first 2 digits ; here len can be 3 or 4 ; Code path for last 2 digits ; Need to explicitly handle 10 - 19. Sum of the two digits is used as index of " two _ digits " array of strings ; Need to explicitely handle 20 ; Rest of the two digit numbers i . e . , 21 to 99 ; Driver Code"
How can the above be solved in Java?

class GFG { static void convert_to_words ( char [ ] num ) { int len = num . length ; if ( len == 0 ) { System . out . println ( " empty ▁ string " ) ; return ; } if ( len > 4 ) { System . out . println ( " Length ▁ more ▁ than ▁ 4 ▁ is ▁ not ▁ supported " ) ; return ; } String [ ] single_digits = new String [ ] { " zero " , " one " , " two " , " three " , " four " , " five " , " six " , " seven " , " eight " , " nine " } ; String [ ] two_digits = new String [ ] { " " , " ten " , " eleven " , " twelve " , " thirteen " , " fourteen " , " fifteen " , " sixteen " , " seventeen " , " eighteen " , " nineteen " } ; String [ ] tens_multiple = new String [ ] { " " , " " , " twenty " , " thirty " , " forty " , " fifty " , " sixty " , " seventy " , " eighty " , " ninety " } ; String [ ] tens_power = new String [ ] { " hundred " , " thousand " } ; System . out . print ( String . valueOf ( num ) + " : ▁ " ) ; if ( len == 1 ) { System . out . println ( single_digits [ num [ 0 ] - '0' ] ) ; return ; } int x = 0 ; while ( x < num . length ) { if ( len >= 3 ) { if ( num [ x ] - '0' != 0 ) { System . out . print ( single_digits [ num [ x ] - '0' ] + " ▁ " ) ; System . out . print ( tens_power [ len - 3 ] + " ▁ " ) ; } -- len ; } else { if ( num [ x ] - '0' == 1 ) { int sum = num [ x ] - '0' + num [ x + 1 ] - '0' ; System . out . println ( two_digits [ sum ] ) ; return ; } else if ( num [ x ] - '0' == 2 && num [ x + 1 ] - '0' == 0 ) { System . out . println ( " twenty " ) ; return ; } else { int i = ( num [ x ] - '0' ) ; if ( i > 0 ) System . out . print ( tens_multiple [ i ] + " ▁ " ) ; else System . out . print ( " " ) ; ++ x ; if ( num [ x ] - '0' != 0 ) System . out . println ( single_digits [ num [ x ] - '0' ] ) ; } } ++ x ; } } public static void main ( String [ ] args ) { convert_to_words ( "9923" . toCharArray ( ) ) ; convert_to_words ( "523" . toCharArray ( ) ) ; convert_to_words ( "89" . toCharArray ( ) ) ; convert_to_words ( "8" . toCharArray ( ) ) ; } }


"Program to convert a given number to words | Set 2 | Java program to print a given number in words . The program handles till 9 digits numbers and can be easily extended to 20 digit number ; Strings at index 0 is not used , it is to make array indexing simple ; Strings at index 0 and 1 are not used , they is to make array indexing simple ; n is 1 - or 2 - digit number ; if n is more than 19 , divide it ; if n is non - zero ; Function to print a given number in words ; stores word representation of given number n ; handles digits at ten millions and hundred millions places ( if any ) ; handles digits at hundred thousands and one millions places ( if any ) ; handles digits at thousands and tens thousands places ( if any ) ; handles digit at hundreds places ( if any ) ; handles digits at ones and tens places ( if any ) ; Driver code ; long handles upto 9 digit no change to unsigned long long int to handle more digit number ; convert given number in words"
How can the above be solved in Java?

class GFG { static String one [ ] = { " " , " one ▁ " , " two ▁ " , " three ▁ " , " four ▁ " , " five ▁ " , " six ▁ " , " seven ▁ " , " eight ▁ " , " nine ▁ " , " ten ▁ " , " eleven ▁ " , " twelve ▁ " , " thirteen ▁ " , " fourteen ▁ " , " fifteen ▁ " , " sixteen ▁ " , " seventeen ▁ " , " eighteen ▁ " , " nineteen ▁ " } ; static String ten [ ] = { " " , " " , " twenty ▁ " , " thirty ▁ " , " forty ▁ " , " fifty ▁ " , " sixty ▁ " , " seventy ▁ " , " eighty ▁ " , " ninety ▁ " } ; static String numToWords ( int n , String s ) { String str = " " ; if ( n > 19 ) { str += ten [ n / 10 ] + one [ n % 10 ] ; } else { str += one [ n ] ; } if ( n != 0 ) { str += s ; } return str ; } static String convertToWords ( long n ) { String out = " " ; out += numToWords ( ( int ) ( n / 10000000 ) , " crore ▁ " ) ; out += numToWords ( ( int ) ( ( n / 100000 ) % 100 ) , " lakh ▁ " ) ; out += numToWords ( ( int ) ( ( n / 1000 ) % 100 ) , " thousand ▁ " ) ; out += numToWords ( ( int ) ( ( n / 100 ) % 10 ) , " hundred ▁ " ) ; if ( n > 100 && n % 100 > 0 ) { out += " and ▁ " ; } out += numToWords ( ( int ) ( n % 100 ) , " " ) ; return out ; } public static void main ( String [ ] args ) { long n = 438237764 ; System . out . printf ( convertToWords ( n ) ) ; } }


"Program to convert centimeter into meter and kilometer | Java program to convert centimeter into meter and kilometer ; Driver Code ; Converting centimeter into meter and kilometer"
How can the above be solved in Java?

import java . io . * ; class GFG { public static void main ( String [ ] args ) { double cm , meter , kilometer ; cm = 1000 ; meter = cm / 100.0 ; kilometer = cm / 100000.0 ; System . out . println ( " Length ▁ in ▁ meter ▁ = ▁ " + meter + " m " ) ; System . out . println ( " Length ▁ in ▁ Kilometer ▁ = ▁ " + kilometer + " km " ) ; } }


"Program to convert polar co | Java code of above approach ; Function to convert degree to radian ; Function to convert the polar coordinate to cartesian ; Convert degerees to radian ; Applying the formula : x = rcos ( theata ) , y = rsin ( theta ) ; Print cartesian coordinates ; Driver code ; Given polar coordinates ; Function to convert polar coordinates to equivalent cartesian coordinates"
How can the above be solved in Java?

import java . util . * ; class GFG { static double ConvertDegToRad ( double degree ) { double pi = 3.14159 ; return ( degree * ( pi / 180.0 ) ) ; } static void ConvertToCartesian ( double [ ] polar ) { polar [ 1 ] = ConvertDegToRad ( polar [ 1 ] ) ; double [ ] cartesian = { polar [ 0 ] * Math . cos ( polar [ 1 ] ) , polar [ 0 ] * Math . sin ( polar [ 1 ] ) } ; System . out . print ( String . format ( " % .3f " , cartesian [ 0 ] ) + " ▁ " + String . format ( " % .3f " , cartesian [ 1 ] ) ) ; } public static void main ( String [ ] args ) { double [ ] polar = { 1.4142 , 45 } ; ConvertToCartesian ( polar ) ; } }


"Program to count digits in an integer ( 4 Different Methods ) | JAVA Code to count number of digits in an integer ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static int countDigit ( long n ) { if ( n / 10 == 0 ) return 1 ; return 1 + countDigit ( n / 10 ) ; } public static void main ( String [ ] args ) { long n = 345289467 ; System . out . print ( " Number ▁ of ▁ digits ▁ : ▁ " + countDigit ( n ) ) ; } }


"Program to count leaf nodes in a binary tree | Class containing left and right child of current node and key value ; Root of the Binary Tree ; Function to get the count of leaf nodes in a binary tree ; Driver program to test above functions ; create a tree ; get leaf count of the abve tree"
How can the above be solved in Java?

class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { Node root ; int getLeafCount ( ) { return getLeafCount ( root ) ; } int getLeafCount ( Node node ) { if ( node == null ) return 0 ; if ( node . left == null && node . right == null ) return 1 ; else return getLeafCount ( node . left ) + getLeafCount ( node . right ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " The ▁ leaf ▁ count ▁ of ▁ binary ▁ tree ▁ is ▁ : ▁ " + tree . getLeafCount ( ) ) ; } }


"Program to count occurrence of a given character in a string | package whatever do not write package name here ; base case ; ; checking if the first character of the given string is that character or not ; this will count the occurrence of given character in the string from index 1 to the last index of the string ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { static int countinString ( char ch , String s ) { if ( s . length ( ) == 0 ) return 0 ; int count = 0 ; if ( s . charAt ( 0 ) == ch ) count ++ ; count += countinString ( ch , s . substring ( 1 ) ) ; return count ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; char c = ' e ' ; System . out . println ( countinString ( c , str ) ) ; } }


"Program to count vowels , consonant , digits and special characters in string . | Java Program to count vowels , consonant , digits and special character in a given string ; Function to count number of vowels , consonant , digitsand special character in a string . ; Declare the variable vowels , consonant , digit and special characters ; str . length ( ) function to count number of character in given string . ; To handle upper case letters ; Driver function ."
How can the above be solved in Java?

import java . io . * ; public class GFG { static void countCharacterType ( String str ) { int vowels = 0 , consonant = 0 , specialChar = 0 , digit = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ( ch >= ' a ' && ch <= ' z ' ) || ( ch >= ' A ' && ch <= ' Z ' ) ) { ch = Character . toLowerCase ( ch ) ; ; if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) vowels ++ ; else consonant ++ ; } else if ( ch >= '0' && ch <= '9' ) digit ++ ; else specialChar ++ ; } System . out . println ( " Vowels : ▁ " + vowels ) ; System . out . println ( " Consonant : ▁ " + consonant ) ; System . out . println ( " Digit : ▁ " + digit ) ; System . out . println ( " Special ▁ Character : ▁ " + specialChar ) ; } static public void main ( String [ ] args ) { String str = " geeks ▁ for ▁ geeks121" ; countCharacterType ( str ) ; } }


"Program to count vowels in a string ( Iterative and Recursive ) | Java program to count vowels in a string ; Function to check the Vowel ; Returns count of vowels in str ; if ( isVowel ( str . charAt ( i ) ) ) Check for vowel ; Driver code ; string object ; Total numbers of Vowel"
How can the above be solved in Java?

public class GFG { static boolean isVowel ( char ch ) { ch = Character . toUpperCase ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } static int countVowels ( String str ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) ++ count ; return count ; } public static void main ( String args [ ] ) { String str = " abc ▁ de " ; System . out . println ( countVowels ( str ) ) ; } }


"Program to count vowels in a string ( Iterative and Recursive ) | Recursive Java program to count the total number of vowels using recursion ; Function to check the Vowel ; to count total number of vowel from 0 to n ; Main Calling Function ; string object ; Total numbers of Vowel"
How can the above be solved in Java?

public class GFG { static int isVowel ( char ch ) { ch = Character . toUpperCase ( ch ) ; if ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) return 1 ; else return 0 ; } static int countVowels ( String str , int n ) { if ( n == 1 ) return isVowel ( str . charAt ( n - 1 ) ) ; return countVowels ( str , n - 1 ) + isVowel ( str . charAt ( n - 1 ) ) ; } public static void main ( String args [ ] ) { String str = " abc ▁ de " ; System . out . println ( countVowels ( str , str . length ( ) ) ) ; } }


"Program to cyclically rotate an array by one |  ; i and j pointing to first and last element respectively ; Driver program"
How can the above be solved in Java?

import java . util . Arrays ; public class Test { static int arr [ ] = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; static void rotate ( ) { int i = 0 , j = arr . length - 1 ; while ( i != j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; i ++ ; } } public static void main ( String [ ] args ) { System . out . println ( " Given ▁ Array ▁ is " ) ; System . out . println ( Arrays . toString ( arr ) ) ; rotate ( ) ; System . out . println ( " Rotated ▁ Array ▁ is " ) ; System . out . println ( Arrays . toString ( arr ) ) ; } }


"Program to determine focal length of a spherical mirror | Java program to determine the focal length of a of a spherical mirror ; Determines focal length of a spherical concave mirror ; Determines focal length of a spherical convex mirror ; Driver function"
How can the above be solved in Java?

 import java . util . * ; import java . lang . * ; public class GfG { public static float focal_length_concave ( float R ) { return R / 2 ; } public static float focal_length_convex ( float R ) { return - ( R / 2 ) ; } public static void main ( String argc [ ] ) { float R = 30 ; System . out . print ( " Focal ▁ length ▁ of " + " spherical ▁ concave " + " mirror ▁ is ▁ : ▁ " + focal_length_concave ( R ) + " units
"); System . out . println ( " Focal ▁ length ▁ of " + " spherical ▁ convex " + " mirror ▁ is ▁ : ▁ " + focal_length_convex ( R ) + " ▁ units " ) ; } }


"Program to determine the Quadrant of a Complex number | Java program to determine the quadrant of a complex number ; Function to determine the quadrant of a complex number ; Storing the index of ' + ' ; Storing the index of ' - ' ; Finding the real part of the complex number ; Finding the imaginary part of the complex number ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static void quadrant ( String s ) { int l = s . length ( ) ; int i ; if ( s . contains ( " + " ) ) { i = s . indexOf ( ' + ' ) ; } else { i = s . indexOf ( ' - ' ) ; } String real = s . substring ( 0 , i ) ; String imaginary = s . substring ( i + 1 , l - 1 ) ; int x = Integer . valueOf ( real ) ; int y = Integer . valueOf ( imaginary ) ; if ( x > 0 && y > 0 ) System . out . print ( " Quadrant ▁ 1" ) ; else if ( x < 0 && y > 0 ) System . out . print ( " Quadrant ▁ 2" ) ; else if ( x < 0 && y < 0 ) System . out . print ( " Quadrant ▁ 3" ) ; else if ( x > 0 && y < 0 ) System . out . print ( " Quadrant ▁ 4" ) ; else if ( x == 0 && y > 0 ) System . out . print ( " Lies ▁ on ▁ positive " + " ▁ Imaginary ▁ axis " ) ; else if ( x == 0 && y < 0 ) System . out . print ( " Lies ▁ on ▁ negative " + " ▁ Imaginary ▁ axis " ) ; else if ( y == 0 && x < 0 ) System . out . print ( " Lies ▁ on ▁ negative " + " ▁ X - axis " ) ; else if ( y == 0 && x > 0 ) System . out . print ( " Lies ▁ on ▁ positive " + " ▁ X - axis " ) ; else System . out . print ( " Lies ▁ on ▁ the ▁ Origin " ) ; } public static void main ( String [ ] args ) { String s = "5 + 3i " ; quadrant ( s ) ; } }


"Program to determine the octant of the axial plane | Java program to print octant of a given point . ; Function to print octant ; Driver Code"
How can the above be solved in Java?

import java . util . * ; class solution { static void octant ( float x , float y , float z ) { if ( x >= 0 && y >= 0 && z >= 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 1st ▁ octant " ) ; else if ( x < 0 && y >= 0 && z >= 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 2nd ▁ octant " ) ; else if ( x < 0 && y < 0 && z >= 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 3rd ▁ octant " ) ; else if ( x >= 0 && y < 0 && z >= 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 4th ▁ octant " ) ; else if ( x >= 0 && y >= 0 && z < 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 5th ▁ octant " ) ; else if ( x < 0 && y >= 0 && z < 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 6th ▁ octant " ) ; else if ( x < 0 && y < 0 && z < 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 7th ▁ octant " ) ; else if ( x >= 0 && y < 0 && z < 0 ) System . out . println ( " Point ▁ lies ▁ in ▁ 8th ▁ octant " ) ; } public static void main ( String args [ ] ) { float x = 2 , y = 3 , z = 4 ; octant ( x , y , z ) ; x = - 4 ; y = 2 ; z = - 8 ; octant ( x , y , z ) ; x = - 6 ; y = - 2 ; z = 8 ; octant ( x , y , z ) ; } }


"Program to determine the quadrant of the cartesian plane | Java program to check quadrant ; Function to check quadrant ; Driver Code ; Function Calling"
How can the above be solved in Java?

import java . io . * ; class GFG { static void quadrant ( int x , int y ) { if ( x > 0 && y > 0 ) System . out . println ( " lies ▁ in ▁ First ▁ quadrant " ) ; else if ( x < 0 && y > 0 ) System . out . println ( " lies ▁ in ▁ Second ▁ quadrant " ) ; else if ( x < 0 && y < 0 ) System . out . println ( " lies ▁ in ▁ Third ▁ quadrant " ) ; else if ( x > 0 && y < 0 ) System . out . println ( " lies ▁ in ▁ Fourth ▁ quadrant " ) ; else if ( x == 0 && y > 0 ) System . out . println ( " lies ▁ at ▁ positive ▁ y ▁ axis " ) ; else if ( x == 0 && y < 0 ) System . out . println ( " lies ▁ at ▁ negative ▁ y ▁ axis " ) ; else if ( y == 0 && x < 0 ) System . out . println ( " lies ▁ at ▁ negative ▁ x ▁ axis " ) ; else if ( y == 0 && x > 0 ) System . out . println ( " lies ▁ at ▁ positive ▁ x ▁ axis " ) ; else System . out . println ( " lies ▁ at ▁ origin " ) ; } public static void main ( String [ ] args ) { int x = 1 , y = 1 ; quadrant ( x , y ) ; } }


"Program to evaluate simple expressions | Java program to evaluate a given expression ; A utility function to check if a given character is operand ; utility function to find value of and operand ; This function evaluates simple expressions . It returns - 1 if the given expression is invalid . ; Base Case : Given expression is empty ; The first character must be an operand , find its value ; Traverse the remaining characters in pairs ; The next character must be an operator , and next to next an operand ; If next to next character is not an operand ; Update result according to the operator ; If not a valid operator ; Driver program to test above function"
How can the above be solved in Java?

class GFG { static boolean isOperand ( char c ) { return ( c >= '0' && c <= '9' ) ; } static int value ( char c ) { return ( int ) ( c - '0' ) ; } static int evaluate ( String exp ) { if ( exp . length ( ) == 0 ) return - 1 ; int res = value ( exp . charAt ( 0 ) ) ; for ( int i = 1 ; i < exp . length ( ) ; i += 2 ) { char opr = exp . charAt ( i ) , opd = exp . charAt ( i + 1 ) ; if ( isOperand ( opd ) == false ) return - 1 ; if ( opr == ' + ' ) res += value ( opd ) ; else if ( opr == ' - ' ) res -= value ( opd ) ; else if ( opr == ' * ' ) res *= value ( opd ) ; else if ( opr == ' / ' ) res /= value ( opd ) ; else return - 1 ; } return res ; } public static void main ( String [ ] args ) { String expr1 = "1 + 2*5 + 3" ; int res = evaluate ( expr1 ) ; if ( res == - 1 ) System . out . println ( expr1 + " ▁ is ▁ Invalid " ) ; else System . out . println ( " Value ▁ of ▁ " + expr1 + " ▁ is ▁ " + res ) ; String expr2 = "1 + 2*3" ; res = evaluate ( expr2 ) ; if ( res == - 1 ) System . out . println ( expr2 + " ▁ is ▁ Invalid " ) ; else System . out . println ( " Value ▁ of ▁ " + expr2 + " ▁ is ▁ " + res ) ; String expr3 = "4-2 + 6*3" ; res = evaluate ( expr3 ) ; if ( res == - 1 ) System . out . println ( expr3 + " ▁ is ▁ Invalid " ) ; else System . out . println ( " Value ▁ of ▁ " + expr3 + " ▁ is ▁ " + res ) ; String expr4 = "1 + + 2" ; res = evaluate ( expr4 ) ; if ( res == - 1 ) System . out . println ( expr4 + " ▁ is ▁ Invalid " ) ; else System . out . println ( " Value ▁ of ▁ " + expr4 + " ▁ is ▁ " + res ) ; } }


"Program to evaluate the expression ( ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¹ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’ Ã ¢ â ‚¬¦¡¬ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¦¡ X + 1 ) ^ 6 + ( ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¹ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’ Ã ¢ â ‚¬¦¡¬ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¦¡ X | Java program to evaluate the given expression ; Function to..."
How can the above be solved in Java?

import java . util . * ; class gfg { public static double calculateSum ( double n ) { return 2 * ( Math . pow ( n , 6 ) + 15 * Math . pow ( n , 4 ) + 15 * Math . pow ( n , 2 ) + 1 ) ; } public static void main ( String [ ] args ) { double n = 1.4142 ; System . out . println ( ( int ) Math . ceil ( calculateSum ( n ) ) ) ; } }


"Program to find Area of Triangle inscribed in N | Java Program to find the area of a triangle inscribed in N - sided regular polygon ; Function to find the area of the polygon ; area of a regular polygon with N sides and side length len ; Function to find the area of a triangle ; area of one triangle in an N - sided regular polygon ; area of inscribed triangle ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static double area_of_regular_polygon ( double n , double len ) { double P = ( len * n ) ; double A = len / ( 2 * Math . tan ( ( 180 / n ) * 3.14159 / 180 ) ) ; double area = ( P * A ) / 2 ; return area ; } static double area_of_triangle_inscribed ( double n , double len ) { double area = area_of_regular_polygon ( n , len ) ; double triangle = area / n ; double ins_tri = ( triangle * 3 ) ; return ins_tri ; } static public void main ( String [ ] arg ) { double n = 6 , len = 10 ; System . out . printf ( " % .3f " , area_of_triangle_inscribed ( n , len ) ) ; } }


"Program to find Circumference of a Circle | Java program to find circumference of circle ; utility function ; driver function"
How can the above be solved in Java?

import java . io . * ; class Geometry { static double circumference ( double r ) { double PI = 3.1415 ; double cir = 2 * PI * r ; return cir ; } public static void main ( String [ ] args ) { double r = 5 ; double result = Math . round ( circumference ( r ) * 1000 ) / 1000.0 ; System . out . println ( " Circumference ▁ = ▁ " + result ) ; } }


"Program to find GCD of floating point numbers | JAVA code for finding the GCD of two floating numbers . ; Recursive function to return gcd of a and b ; base case ; Driver Function ."
How can the above be solved in Java?

import java . io . * ; class GFG { static double gcd ( double a , double b ) { if ( a < b ) return gcd ( b , a ) ; if ( Math . abs ( b ) < 0.001 ) return a ; else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ; } public static void main ( String args [ ] ) { double a = 1.20 , b = 22.5 ; System . out . printf ( " % .1f " , gcd ( a , b ) ) ; } }


"Program to find GCD or HCF of two numbers | Java program to find GCD of two numbers ; Recursive function to return gcd of a and b ; Driver method"
How can the above be solved in Java?

class Test { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int a = 98 , b = 56 ; System . out . println ( " GCD ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + gcd ( a , b ) ) ; } }


"Program to find GCD or HCF of two numbers | Java program to find GCD of two numbers ; Recursive function to return gcd of a and b ; Everything divides 0 ; base case ; a is greater ; Driver method"
How can the above be solved in Java?

class Test { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } public static void main ( String [ ] args ) { int a = 98 , b = 56 ; System . out . println ( " GCD ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + gcd ( a , b ) ) ; } }


"Program to find Greatest Common Divisor ( GCD ) of N strings | Java program for the above approach ; Function that finds gcd of 2 strings ; If str1 length is less than that of str2 then recur with gcd ( str2 , str1 ) ; If str1 is not the concatenation of str2 ; GCD string is found ; Cut off the common prefix part of str1 & then recur ; Function to find GCD of array of strings ; Return the GCD of strings ; Driver Code ; Given array of strings ; Function Call"
How can the above be solved in Java?

class GCD { static String gcd ( String str1 , String str2 ) { if ( str1 . length ( ) < str2 . length ( ) ) { return gcd ( str2 , str1 ) ; } else if ( ! str1 . startsWith ( str2 ) ) { return " " ; } else if ( str2 . isEmpty ( ) ) { return str1 ; } else { return gcd ( str1 . substring ( str2 . length ( ) ) , str2 ) ; } } static String findGCD ( String arr [ ] , int n ) { String result = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { result = gcd ( result , arr [ i ] ) ; } return result ; } public static void main ( String [ ] args ) { String arr [ ] = new String [ ] { " GFGGFG " , " GFGGFG " , " GFGGFGGFGGFG " } ; int n = arr . length ; System . out . println ( findGCD ( arr , n ) ) ; } }


"Program to find HCF ( Highest Common Factor ) of 2 Numbers | Java program to find GCD of two numbers ; Recursive function to return gcd of a and b ; Driver method"
How can the above be solved in Java?


"Program to find HCF ( Highest Common Factor ) of 2 Numbers | Java program to find GCD of two numbers ; Recursive function to return gcd of a and b ; Everything divides 0 ; base case ; a is greater ; Driver method"
How can the above be solved in Java?

class Test { static int gcd ( int a , int b ) { if ( a == 0 && b == 0 ) return 0 ; if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } public static void main ( String [ ] args ) { int a = 98 , b = 56 ; System . out . println ( " GCD ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + gcd ( a , b ) ) ; } }


"Program to find LCM of 2 numbers without using GCD | Java program to find LCM of 2 numbers without using GCD ; Function to return LCM of two numbers ; Driver program to test above function"
How can the above be solved in Java?

import java . io . * ; import java . lang . * ; class GfG { public static int findLCM ( int a , int b ) { int lar = Math . max ( a , b ) ; int small = Math . min ( a , b ) ; for ( int i = lar ; ; i += lar ) { if ( i % small == 0 ) return i ; } } public static void main ( String [ ] argc ) { int a = 5 , b = 7 ; System . out . println ( " LCM ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + findLCM ( a , b ) ) ; } }


"Program to find LCM of two Fibonnaci Numbers | Java program to find LCM of Fib ( a ) and Fib ( b ) ; Create an array for memoization ; Function to return the n 'th Fibonacci number using table f[]. ; Base cases ; If fib ( n ) is already computed ; Applying recursive formula Note value n & 1 is 1 if n is odd , else 0. ; Function to return gcd of a and b ; Function to return the LCM of Fib ( a ) and Fib ( a ) ; Driver code"
How can the above be solved in Java?

import java . util . * ; class GFG { static int MAX = 1000 ; static int [ ] f = new int [ MAX ] ; static int fib ( int n ) { if ( n == 0 ) return 0 ; if ( n == 1 n == 2 ) return ( f [ n ] = 1 ) ; if ( f [ n ] != 0 ) return f [ n ] ; int k = 0 ; if ( ( n & 1 ) != 0 ) k = ( n + 1 ) / 2 ; else k = n / 2 ; if ( ( n & 1 ) != 0 ) f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) ; else f [ n ] = ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; return f [ n ] ; } static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int findLCMFibonacci ( int a , int b ) { return ( fib ( a ) * fib ( b ) ) / fib ( gcd ( a , b ) ) ; } public static void main ( String args [ ] ) { int a = 3 , b = 12 ; System . out . println ( findLCMFibonacci ( a , b ) ) ; } }


"Program to find LCM of two numbers | Java program to find LCM of two numbers . ; Recursive method to return gcd of a and b ; method to return LCM of two numbers ; Driver method"
How can the above be solved in Java?

class Test { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int lcm ( int a , int b ) { return ( a / gcd ( a , b ) ) * b ; } public static void main ( String [ ] args ) { int a = 15 , b = 20 ; System . out . println ( " LCM ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + lcm ( a , b ) ) ; } }


"Program to find Length of Bridge using Speed and Length of Train | Java Program to implement above code . ; function to calculate the length of bridge . ; Driver Code ; Assuming the input variables"
How can the above be solved in Java?

public class GFG { static int bridge_length ( int trainLength , int Speed , int Time ) { return ( ( Time * Speed ) - trainLength ) ; } public static void main ( String [ ] args ) { int trainLength = 120 ; int Speed = 30 ; int Time = 18 ; System . out . print ( " Length ▁ of ▁ bridge ▁ = ▁ " + bridge_length ( trainLength , Speed , Time ) + " ▁ meters " ) ; } }


"Program to find Length of Latus Rectum of an Ellipse | Java program for the above approach ; Function to calculate the length of the latus rectum of an ellipse ; Length of major axis ; Length of minor axis ; Length of the latus rectum ; Driver code ; Given lengths of semi - major and semi - minor axis ; Function call to calculate length of the latus rectum of a ellipse"
How can the above be solved in Java?

import java . util . * ; 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 . print ( lengthOfLatusRectum ( A , B ) ) ; } }


"Program to find Nth odd Fibonacci Number | Java program for Nth odd fibonacci number ; Function to find nth odd fibonacci number ; Driver Code"
How can the above be solved in Java?

class GFG { static int oddFib ( int n ) { n = ( 3 * n + 1 ) / 2 ; int a = - 1 , b = 1 , c = 0 , i ; for ( i = 1 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return c ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( oddFib ( n ) ) ; } }


"Program to find Nth term divisible by a or b | Java program to find nth term divisible by a or b ; Function to return gcd of a and b ; Function to calculate how many numbers from 1 to num are divisible by a or b ; calculate number of terms divisible by a and by b then , remove the terms which is are divisible by both a and b ; Binary search to find the nth term divisible by a or b ; set low to 1 and high to max ( a , b ) * n , here we have taken high as 10 ^ 18 ; if the current term is less than n then we need to increase low to mid + 1 ; if current term is greater than equal to n then high = mid ; Driver code"
How can the above be solved in Java?

class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int divTermCount ( int a , int b , int lcm , int num ) { return num / a + num / b - num / lcm ; } static int findNthTerm ( int a , int b , int n ) { int low = 1 , high = Integer . MAX_VALUE , mid ; int lcm = ( a * b ) / gcd ( a , b ) ; while ( low < high ) { mid = low + ( high - low ) / 2 ; if ( divTermCount ( a , b , lcm , mid ) < n ) low = mid + 1 ; else high = mid ; } return low ; } public static void main ( String [ ] args ) { int a = 2 , b = 5 , n = 10 ; System . out . println ( findNthTerm ( a , b , n ) ) ; } }


"Program to find Nth term of series 0 , 10 , 30 , 60 , 99 , 150 , 210 , 280. ... ... ... . | Java program to find the N - th term of the series : 0 , 10 , 30 , 60 , 99 , 150 , 210 , ... . . ; 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 5 * ( int ) Math . pow ( n , 2 ) - 5 * n ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find Nth term of series 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203 , ... . | Java program to find the N - th term of the series : 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203. . ... ; 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 3 * ( int ) Math . pow ( n , 2 ) + 2 * n - 5 ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find Nth term of series 0 , 7 , 18 , 33 , 51 , 75 , 102 , 133 , ... . . | Java program to find the N - th term of the series : 0 , 7 , 18 , 33 , 51 , 75 , 102 , ... . . ; 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 2 * ( int ) Math . pow ( n , 2 ) + n - 3 ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find Nth term of series 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147 , ... . . | Java program to find the N - th term of the series : 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147. . ... ; calculate Nth term of series ; Driver code"
How can the above be solved in Java?

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


"Program to find Nth term of series 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . | Java program to find the N - th term of the series : 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . ; calculate Nth term of series ; Driver program"
How can the above be solved in Java?

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


"Program to find Nth term of series 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . | Java program to find the N - th term of the series : 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . ; calculate Nth term of series ; Driver code"
How can the above be solved in Java?

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


"Program to find Nth term of series 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . | Java program to find the N - th term of the series : 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . ; 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 ) + 4 * n - 2 ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find Nth term of series 9 , 23 , 45 , 75 , 113. . . | Java program to find N - th term of the series : 9 , 23 , 45 , 75 , 113. . . ; 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 ( 2 * N + 3 ) * ( 2 * N + 3 ) - 2 * N ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }


"Program to find Nth term of the series 3 , 12 , 29 , 54 , 87 , ... | Java program to find N - th term of the series : 3 , 12 , 29 , 54 , 87 , ... ; calculate Nth term of series ; Return Nth term ; Driver code ; 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 4 * ( long ) Math . pow ( N , 2 ) - 3 * N + 2 ; } public static void main ( String arr [ ] ) { long N = 10 ; System . out . println ( getNthTerm ( N ) ) ; } }


"Program to find Perimeter / Circumference of Square and Rectangle | Java program to find Circumference of a square ; Driver code"
How can the above be solved in Java?

import java . io . * ; class GFG { int Circumference ( int a ) { return 4 * a ; } public static void main ( String args [ ] ) { GFG obj = new GFG ( ) ; int a = 5 ; System . out . println ( " Circumference ▁ of ▁ " + " a ▁ square ▁ is ▁ " + obj . Circumference ( a ) ) ; } }