Java Program:

- To print Even numbers between 1 to N

Example:

User Input: 9

Output: 2 4 6 8

import java.util.Scanner;
public class EvenNumbers {
  public static void main(String []args) {
    int num;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter your last number : ");
    num = userInput.nextInt();

    System.out.print("Your even numbers are :");
    for (int i=1; i<num; i++)
      if(i%2==0)System.out.print(i+" ");
  }
}

Output:

  Enter your last number : 7
  Your even numbers are : 2 4 6
Program
basic

You should know first :

Even numbers: Numbers perfectly divisible by 2

(number % 2 == 0)

So, we are using a for loop till the last number entered and check every value for even

for(int i=0; i<LastValue; i++) {
  //Check every 'i' for even, if even then print
}
Concept

Coming Soon !

Quick
Tutorial

Quote

Sometimes it’s the smallest decisions that can change your life forever.