Question: JAVA Code: Write a program that prints a table of the powers of 2 from 20 up to 2n where n is a given positive

JAVA Code:

Write a program that prints a table of the powers of 2 from 20 up to 2n where n is a given positive integer input from the user. Use four spaces to separate the value of i and 2i in the output. Note: Math.pow() returns a double, but your output should be integers.

Example output of program:

Enter a positive integer: 6 i 2^i 0 1 1 2 2 4 3 8 4 16 5 32 6 64

Starter Code:

import java.util.Scanner; public class PowersOf2 { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //TODO: complete the program } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!