Looping
for
public class example{public static void main(String[] args)
{
for(int i = 1;i <= 5;i++){
System.out.print(i);
System.out.println();
}
}
}
while
class fact {
public static void main(String args[])
{
int value=5, factorial = 1,temp=value ;
while (temp > 0) {
factorial *= temp;
temp--;
}
System.out.println("The factorial of " + value + " is " + factorial + ".");
}
}
No comments:
Post a Comment