Friday, January 23, 2015

Printing the even numbers between 1 to 100 in java program


The java program given below will print all the even numbers between 1 to 100. To do so I have used do...while loop. Inside the loop I have used an if statement to check if the number is even or not.
printing even numbers,do while loop
public class EvenNum{
 public static void main(String arg []){
  int i=1;
  do{
   if(i%2==0){
   System.out.print(i+", ");
  }
   i++;
  } while (i<=100);
 }
}


No comments:

Post a Comment