- Joined
- Nov 24, 2004
- Messages
- 147
- Reaction score
- 2
Hi all,
i have some issues with some calculation below.
Test run 1:
a = 2
b = 12
Test run 1 generate this output: 4 8 12
Test run 2:
a = 21
b = 15
Test run 2 generate this output: 16 20
If the size is change to 5:
Using int a = 6, b = 12 as inputs. It displays the following output: 5 10 --> Which is incorrect. Exact value should be 10 (Multiple of 5 --> 2 X 5 = 10)
How to improve the code above for better flexibility?
i have some issues with some calculation below.
Code:
public static final int SIZE = 4;
int a = 2;
int b = 12;
// Multiple of 4 between a and b (inclusive) in ascending order
for (int i = (Math.min(a,b) + 1) / size; i <= Math.max(a,b) / size; i++){
System.out.print(i * size + " ");
}
Test run 1:
a = 2
b = 12
Test run 1 generate this output: 4 8 12
Test run 2:
a = 21
b = 15
Test run 2 generate this output: 16 20
If the size is change to 5:
Using int a = 6, b = 12 as inputs. It displays the following output: 5 10 --> Which is incorrect. Exact value should be 10 (Multiple of 5 --> 2 X 5 = 10)
How to improve the code above for better flexibility?