Computer Applications
Write a program that accepts a number x and then prints:
x0, x1, x2, x3, x4, x5
Answer
import java.util.Scanner;
public class KboatXPower
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter x: ");
int x = in.nextInt();
System.out.print(Math.pow(x, 0) + ", ");
System.out.print(Math.pow(x, 1) + ", ");
System.out.print(Math.pow(x, 2) + ", ");
System.out.print(Math.pow(x, 3) + ", ");
System.out.print(Math.pow(x, 4) + ", ");
System.out.print(Math.pow(x, 5));
}
}
Output
Related Questions
Write the equivalent Java statements for the following, by using the mathematical functions:
i. Print the positive value of -999.
ii. Store the value -3375 in a variable and print its cube root.
iii. Store the value 999.99 in a variable and convert it into its closest integer that is greater than or equal to 999.99.
Write a program to generate random integers in the following ranges:
i. 10 to 20 (both inclusive)
ii. 25 to 50 (both inclusive)