I need to find the first 16 multiples of 2 starting with 2. Then find the product in the next line like this. I need to use for loops only.
Sample output: 2 4 6 8 10 12 ...
The product is ______
I tried this. For loops only.
import java.util.Scanner;
public class Program30
{
public static void main(String args[]) {
int a,b;
b=2*4*6*10*12*14*16*18*20*22*24*26*28*30*32;
for(int x=1;x<=16;x++) {
a=2*x;
System.out.print(a+" ");
}
System.out.println("\nThe product is "+b);
}
}
Is there a better way to do this? Thank you.
On the hardcoded try you are missing the number 8.