KnowledgeBoat Logo

Computer Applications

Write a program to compute and display the value of expression:

1x2+1y3+1z4\dfrac{1}{x^2} + \dfrac{1}{y^3} + \dfrac{1}{z^4}

where, the values of x, y and z are entered by the user.

Java

Java Math Lib Methods

ICSE

9 Likes

Answer

import java.util.Scanner;

public class KboatExpression
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        System.out.print("Enter x: ");
        int x = in.nextInt();
        System.out.print("Enter y: ");
        int y = in.nextInt();
        System.out.print("Enter z: ");
        int z = in.nextInt();
        
        double result = 1 / Math.pow(x, 2) + 1 / Math.pow(y, 3) + 1 / Math.pow(z, 4);
        
        System.out.println("Result = " + result);
    }
}

Output

BlueJ output of Write a program to compute and display the value of expression: where, the values of x, y and z are entered by the user.

Answered By

2 Likes


Related Questions