- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
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:
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
