KnowledgeBoat Logo
LoginJOIN NOW

Computer Applications

Write a complete Java program that invokes a function satis() to find whether four integers a, b, c, d sent to satis( ) satisfy the equation a3 + b3 + c3 = d3 or not. The function satis( ) returns 0 if the above equation is satisfied with the given four numbers otherwise it returns -1.

Java

User Defined Methods

12 Likes

Answer

import java.util.Scanner;

class KboatCheckEquation
{
    int satis(int p, 
                int q, 
                int r, 
                int s) {
        int res;
        
        double lhs = Math.pow(p,3) 
                     + Math.pow(q,3) 
                     + Math.pow(r,3);
                     
        double rhs = Math.pow(s,3);
        
        if(lhs == rhs) 
           res = 0;
        else
            res = -1;
            
        return res;
    }
    
    public static void main(String args[])
    {
        KboatCheckEquation obj = new KboatCheckEquation();
        
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a: " );
        int a = in.nextInt();
        System.out.print("Enter b: " );
        int b = in.nextInt();
        System.out.print("Enter c: " );
        int c = in.nextInt();
        System.out.print("Enter d: " );
        int d = in.nextInt();
                
        int res = obj.satis(a, b, c, d);
        
        if(res == 0)
            System.out.println("Equation satisfied");
        else
            System.out.println("Equation not satisfied");
    }    
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a complete Java program that invokes a function satis() to find whether four integers a, b, c, d sent to satis( ) satisfy the equation a 3 + b 3 + c 3 = d 3 or not. The function satis( ) returns 0 if the above equation is satisfied with the given four numbers otherwise it returns -1.BlueJ output of Write a complete Java program that invokes a function satis() to find whether four integers a, b, c, d sent to satis( ) satisfy the equation a 3 + b 3 + c 3 = d 3 or not. The function satis( ) returns 0 if the above equation is satisfied with the given four numbers otherwise it returns -1.

Answered By

2 Likes


Related Questions