Sunday 3 August 2014

How to use DO WHILE LOOP IN JAVA

Structure of the Problem Requirements 

In the previous lesson we learn how to use while loop in Java to take the input from the user and again display them with while loop. Here is another type of loop which is known as do while loop. The Functionality of do while loop is close enough to while loop but the main difference is that do while loop check the statement after the execution and while loop first . Here is the source code of do while loop which help you to understand better.


Source Code 


package com.ancodingpoint.www;

import java.util.Scanner;

public class Loops{

 public static void main(String[] args) {
    Scanner input = new Scanner (System.in);
     int num [] = new int [5];
     int a =0;
     int b =0;
     do
     {
         System.out.println(" Enter Your Number......! ");
         num[a] = input.nextInt();
         a++;
     } 
     while (a<5);
     
  System.out.println(" Again Printing these Numbers with do-while Loop");
  do{
      System.out.println(num[b]);
      b++;
  }
  while (b<5);
     }
 }   

Output of the Program








Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment