
Patrick B. answered 07/15/19
Math and computer tutor/teacher
import java.io.*;
class Power2
{
private int N;
Console console;
Power2()
{
console = System.console();
N=0;
}
public void Go()
{
String inbuff;
int pow2 = 1;
try
{
N=0;
while (N<1)
{
System.out.print(" Please input a positive integer :> ");
inbuff = console.readLine();
N = Integer.parseInt(inbuff);
}
int expo=0;
while (pow2<=N)
{
System.out.println(" 2 to the power of " + expo + " is " + pow2);
expo++; pow2 *=2;
}
} //try
catch (Exception ex)
{
System.out.println(" An input error has occured ");
}
} //Go
public static void main(String args[])
{
Power2 myPower2 = new Power2();
myPower2.Go();
} //main
} //class