To declare an array in a Java program, we must declare a variable to reference the array and we most specify the type of array the variable can reference.
Syntax:
dataType[] arrayRefVar;
or
dataType arrayRefVar[];
import java.util.Scanner; class EvenArray{ public static void main(String args[]){ Scanner in = new Scanner(System.in); int x, y; System.out.print("Enter First Number : "); x = in.nextInt(); System.out.print("Enter Second Number : "); y = in.nextInt(); for(int i=x; i<=y; i++){ if(i%2==0){ System.out.println(i); } } } }
Post a Comment