Sunday, March 13, 2016

Java Examples : How To Use Do While Loop Statement

Intro


This examples, will demonstrates how to use Do While Loop statement using Java program.

Examples


package com.freesamplecode.java.basic;

public class DoWhileLoopDemo {
     public static void main(String[] args){
          //print numeric value from 1 to 5
          int i = 1;
         
          do{
             System.out.println(i);
             i++;

          }while(i < 6);

          System.out.println("\n");

          char[] chars = {'L','e','a','r','n','i','n','g'};

          // print string learning using char array
          int j = 0;

          do{
             System.out.print(chars[j]);
             j++;
          }while(j < chars.length);

     }
}


Output


1
2
3
4
5


Learning

Screenshot

How To Use Do While Loop Statement In Java

Related Posts:

0 comments: