Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Mathematical Library Methods

Chapter 7

Mathematical Library Methods

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Evaluate the Expression


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

1x2+1y3+1z4

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

import java.util.Scanner;

 

public class ExpressionCalculation {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        // Input values

        System.out.print("Enter value of x: ");

        double x = sc.nextDouble();

 

        System.out.print("Enter value of y: ");

        double y = sc.nextDouble();

 

        System.out.print("Enter value of z: ");

        double z = sc.nextDouble();

 

        // Calculate expression

        double result = (1 / Math.pow(x, 2)) +

                        (1 / Math.pow(y, 3)) +

                        (1 / Math.pow(z, 4));

 

        // Output

        System.out.println("Value of the expression = " + result);

 

        sc.close();

    }

}

Output


Sample Input 
Enter value of x: 2
Enter value of y: 2
Enter value of z: 2

Sample Output 
Value of the expression = 0.6875

Explanation

  • The given expression is split into three terms:
    • 1/x2
    • 1/y3
    • 1/z4
  • Math.pow(base, exponent) is used to calculate powers.
  • double data type is used to ensure accurate division results.

Calculation for sample input:

1/22 + 1/23 + 1/24 = 1/4 + 1/8 + 1/16 = 0.25 + 0.125 + 0.0625 = 0.4375