Uses a while loop to print the even numbers from 2 through 20 on the console - Java Language Basics

Java examples for Language Basics:while

Description

Uses a while loop to print the even numbers from 2 through 20 on the console

Demo Code

public class EvenCounter
{
  public static void main(String[] args)
  {//from   ww w . j a va2  s  . co  m
    int number = 2;
    while (number <= 20)
    {
      System.out.print(number + " ");
      number += 2;
    }
    System.out.println();
  }

}

Related Tutorials