WHILE LOOP IN JAVA

There is not much difference between for loop and while loop. The main difference is that the for loop contain its all condition and statement within the loop and on the other hand in while loop the condition is outside of the loop.

Source Code


package com.ancodingpoint.www;

import java.util.Scanner;

public class While_Loop{

 public static void main(String[] args) {

     Scanner input = new Scanner (System.in);
     int num [] = new int [5];
     int a =0;
     int b =0;
     while (a<5)
     {
         System.out.println(" Enter Your Number Here ...... !");
         num[a] = input.nextInt();
         a++;
         
     }
     System.out.println("  Now Again printing these Number with using While Loop ");
 while (b<5)   
 {
     System.out.println(num[b]);
     b++;
 }
     }
 }

Output of the Program


Java Programming


Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment