Find and list even numbers between 1 and any given number - Java Language Basics

Java examples for Language Basics:int

Description

Find and list even numbers between 1 and any given number

Demo Code


public class Main {
        public static void main(String[] args) {
                int limit = 50;
                System.out.println("Printing Even numbers between 1 and " + limit);
                for(int i=1; i <= limit; i++){
                        if( i % 2 == 0){
                                System.out.print(i + " ");
                        }/*from www . j a  va 2s.c o  m*/
                }
        }
}
 

Result


Related Tutorials