Showing posts with label While Loop in Java. Show all posts
Showing posts with label While Loop in Java. Show all posts

Sunday, 3 August 2014

How to USE WHILE LOOP IN JAVA

Structure of the Problem Requirements 


In the previous lesson we learn how to use for loop in Java . In this lesson we again print the same thing but this time with While loop. 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
Java While Loop