- 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: Print Powers of a Number
Write a program that accepts a number x and then prints:
x0, x1, x2, x3, x4, x5
import java.util.Scanner;
public class PowersOfX {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input value
System.out.print("Enter the value of x: ");
int x = sc.nextInt();
// Print powers from x^0 to x^5
System.out.println("Powers of x are:");
for (int i = 0; i <= 5; i++) {
System.out.println("x^" + i + " = " + Math.pow(x, i));
}
sc.close();
}
}
Output
Sample Input Enter the value of x: 2 Sample Output Powers of x are: x^0 = 1.0 x^1 = 2.0 x^2 = 4.0 x^3 = 8.0 x^4 = 16.0 x^5 = 32.0
Explanation
- Math.pow(x, i) computes x raised to the power i.
- A for loop runs from 0 to 5 to generate all required powers.
- x⁰ is always 1 for any non-zero x.
