What is while loop?
Java while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.
syntax:
Example program1:
// Given a num, returns how many times can we divide it by 2 to get down to 1.
int count2Div(int num) {
int count = 0; // count how many divisions we've done
while (num >= 1) {
num = num / 2;
count++;
}
return count;
}
Example program 2:
{
int count=0;
while(count<=5)
{
int mark=90;
Count=count+1;
}
Scanner class:
Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings. It is the easiest way to read input in a Java program, though not very efficient if you want an input method for scenarios where time is a constraint like in competitive programming.
Example:
{
int count=0;
while (count<=5)
{
System.out.println("enter marks") ;
Scanner. scanner=new scanner(System.in) ;
int mark=Scanner.nextInt() ;
Count=count+1;
System.out.println(count) ;
}
Import:
import is a keyword. import keyword is used to import built-in and user-defined packages into your java source file so that your class can refer to a class that is in another package by directly using its name.
Reference by=quora.com,geeksforgeeks.com