Friday 17 November 2017

Java Program to Find Maximum Value of any Algebraic Expression


Code:

public static void main(String[] args) {

    int num;
    double sqrtnum;
    double dividedsqrtnum;
    double f;
    int x = 0;
    float a;
    int d;
    float p;
    int q;

     Scanner input = new Scanner(System.in);

      System.out.println("Enter the number 'N'");
     num = input.nextInt();

     if( (num % 3) != 0){

         System.out.println( "The number you entered is a semi-prime");

         sqrtnum = Math.sqrt(num);

         dividedsqrtnum = sqrtnum / 18;

         f = Math.ceil(dividedsqrtnum) ;

         System.out.println("The value of f is " + f);

         // Algebraic expressions

         for (x=0; x <= f; x++){

             while (d == 1 || x ==f){

         a = (num - 1 - 18 * x);
    d = findGCD(num,a);
        if ( d == 1){

        x = x++;
        }

        else{
            q = d;
            p = (a / q + 1);

            System.out.println("The divisors of "+ num +" are "+ p +" and " + q +" do you want to test another number? Y or N " );
            }

                    }
                                }
                            }

     else{
         System.out.println("The number is not a semi-prime");

     }
}

 private static int findGCD(float num,float a) {
        //base case

        return findGCD(a, num%a);
    }

}


Output:

Execute and get the output.



More Java Programs:













100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...