0
Is there any easier way of multiplying numbers in Java?
Is there an easier way of multiplying numbers. I mean usually we use for(int i=1; i< 100; i++ or (i--)) for increment or decrement part. But how can we write this code: product of 15 or 20 numbers from 1to 15, 20?
4 Antworten
+ 1
i *= 15 or i *= 20?
+ 1
Then you would need another variable:
int x = 1;
for (int i = 1; i <= 10; i++) {
x *= i;
}
+ 1
Thank you Seb TheS. Now it outputs the code I wanted
0
Seb TheS. You mean for(int=1; I<=10; i*=10){
But if I run this code it outputs
1
10
But I want code to multiple numbers:
1*2*3*4*5*6*7*8*9*10=3628800
Result should be like this.
Or is this the only way to get the result.