While Loop
It is a control statement. All the statements will execute repetatively until the condition became false.
Syntax:-
while(condition)
{
statements;
}
PROGRAM TO PRINT THE SUM OF TEN NUMBERS.
class Sum
{
public static void main(String args[])
{
int a=0,b=1;
while(b<=10)
{
a=a+b;
b++;
}
System.out.println("Sumof: "+a);
}
}
PROGRAM TO FIND THE FACTORIAL VALUE.
class Fact
{
public static void main(String args[])
{
int n=1,b=1;
while(b<=5)
{
n=n*b;
b++;
}
System.out.println("Factorial: "+n);
}
}
For
More Explanation
&
Online Classes
More Explanation
&
Online Classes
Contact Us:
+919885348743
+919885348743