> while Statement in java ~ Online tutorial

while Statement in java

The while Statement
The while statement executes an Expression and a Statement repeatedly until the
value of the Expression is false.
WhileStatement:
while ( Expression ) Statement
WhileStatementNoShortIf:
while ( Expression ) StatementNoShortIf


The Expression must have type boolean or Boolean, or a compile-time error
occurs.
A while statement is executed by first evaluating the Expression. If the result
is of type Boolean, it is subject to unboxing conversion (§5.1.8). If evaluation of
the Expression or the subsequent unboxing conversion (if any) completes abruptly
for some reason, the while statement completes abruptly for the same reason.
Otherwise, execution continues by making a choice based on the resulting value:
• If the value is true, then the contained Statement is executed. Then there is a
choice:
•If execution of the Statement completes normally, then the entire while
statement is executed again, beginning by re-evaluating the Expression.
• If execution of the Statement completes abruptly, see §14.12.1 below.
• If the (possibly unboxed) value of the Expression is false, no further action
is taken and the while statement completes normally.
If the (possibly unboxed) value of the Expression is false the first time it is evaluated,
then the Statement is not executed.
Program
import java.io.*;
public class whiledat
{
public static void main(String args[])throws IOException
{
int n=0;
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the no");
String text=in.readLine();
int m=Integer.parseInt(text);
while(n<=5) 
{
 int a=m%10; 
int b=a*a*a;
 System.out.println("welcome to java");
 n++; 

}
 }






Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: