Hello everyone!
So I'm just at a wall right now. I'm a very very beginner java programmer. I currently have to write a program that displays a table. The user will enter the base number, then the maximum exponent. It will then be displayed like so:
Enter the base: 2
Enter the maximum exponent: 7
The base is 2 and the maximum exponent is 7.
Powers of 2
x 2^x
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
I have to use for loops.
If someone could explain a loop that can carry out this function, then it would be greatly greatly appreciated.
I can post what I currently have in order to see I am making an effort (Although the for loops are way way off.) I am not on here to ask for straight answers, but to instead build onto my knowledge of Java. Any help is appreciated and thank you very much in advance!
Here's my code: (Totally lost)
import java.util.*; public class Practice { public static void main(String[] args) { Scanner kb = new Scanner(System.in); int b = kb.nextInt(); int y = kb.nextInt(); int result = b ^ y; for(result = 1; result <= y; result = result * b){ System.out.print("\t " + result); System.out.print("\n"); } } }