KnowledgeBoat Logo

Computer Applications

Write a program that accepts a number x and then prints:

x0, x1, x2, x3, x4, x5

Java

Java Math Lib Methods

11 Likes

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

BlueJ output of Write a program that accepts a number x and then prints: x 0 , x 1 , x 2 , x 3 , x 4 , x 5

Answered By

6 Likes


Related Questions