Intro
This examples, will demonstrates how to use while loop statement in Java program. While Loop statement is used to executes a statement as long as the boolean condition evaluates to true.
Examples
package com.freesamplecode.java.basic;
public class WhileLoopDemo {
public static void main(String[] args){
//print numeric value from 1 to 5
int i = 0;
while(i <6){
System.out.println(i);
i++;
}
System.out.println("\n");
char[] chars = {'L','e','a','r','n','i','n','g'};
// print string learning using char array
int j = 0;
while(j <chars.length){
System.out.print(chars[j]);
j++;
}
}
}
Ouput
0
1
2
3
4
5
Learning
Screenshot
0 comments: