Computer Notes, Programming codes, Hardware and Networking Tip, Entertainment, Biography, Internet Tip, Tech News, Latest Technology, YouTube,

How array can be declared in Java? Write a complete Java program to read two numbers from the user (where first number is less then second number) then find only even number between them.

Java, Java question answer, java array declaration, java program to print even number between any two numbers, Java program to read two numbers from the user (where first number is less then second number) then find only even number between them,

Array is a data structure which contains of similar data type. We store only fixed set of elements in a java array. Array is used to store a collection of data, but it is often more useful to think of an array as a collection of variable of the same type.

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[];


Program
 

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

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget