never thought i had issues with nested loops well here Iam: What i want to achieve is this: Given two number A and B i need to find all counting numbers between 1 and the A*B for example A=4 B=3 i need this:
1 2 3
4 5 6
7 8 9
10 11 12
I wrote the initial parts but i can’t figure out how can i write down the value which changes in every row
for(int i=1; i<=A; i++){
for(int j=1; j<=B; j++){
System.out.println("?");}}
Having A*B gives me
1 2 3
2 4 6
3 6 9
4 8 12
I tried some other combinations too but to no luck, It might look straight forward but its the first time i’m facing this. Thanks in advance!
You can try
(i-1)*B + j.Another option is to just use 1 for loop: