0

can someone help me find something that i can depend on making sourcecodes using while, do while, for while...thx

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by vaibhav1983
0

For example, to get the factorial of n where n is in int. The result is the final value of fac.

long fac=1;
int i=1;
while ( i<=n ) { // the condition for execution of the loop
fac *= i;  //  the previous factorial (factorial of i-1)is multiplied by the current i
i++;  // i has one increment
}
long fac=1;
int i=1;
do{
fac *= i; //  the previous factorial (factorial of i-1)is multiplied by the current i

i++; // i has one increment
}while ( i<=n ) // the condition for execution of the loop
long fac=1;
for (int i=1; i<=n; i++) // the control variable i is initiated with 1
fac = fac*i; //  the previous factorial (factorial of i-1)is multiplied by the current i

also see http://download.oracle.com/javase/tutorial/java/nutsandbolts/while.html

Edited by tong1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.