While Loop in Java. | Coding Startup

While Loop in Java.

While Loop in Java.

100% Working Code and Projects.


if you need any help about project and Application Contact Shelly at:+917888361589.


Java Code given below:-


package CodingStartupAbheer;

import java.util.Scanner;

public class WhileLoop {

    public static void main(String Abheer[]) {
        Scanner s = new Scanner(System.in);
        System.out.println("Enter your name");
        String a = s.nextLine();
        System.out.println("How many times yo want to print name");
        int q = s.nextInt();
        int i = 1;
        while (i <= q) {
            System.out.println(a);
            i++;
        }

    }

}


Output:-

Enter your name
Abheer
How many times yo want to print name
2
Abheer
Abheer



Explanation:-

In this loop, firstly the condition will be checked then it will execute the inner statement in the blocks. The drawback of Do While loop is over come in this loop.





Code Startup

Author & Editor

0 Comments:

Post a Comment