public class PowersOfTwo { public static void main(String[] args) { //Read input int N = Integer.parseInt(args[0]); //2^0 is 1, so this is base case int powerOfTwo = 1; for(int i = 0; i <= N; i++) //i++ equivalent to i = i + 1 { System.out.println(Math.pow(2,i)+" = "+powerOfTwo); powerOfTwo = powerOfTwo*2; } } }