Best Answer

If(array[] % 2 == 0){ //checks the remainder, if its even then the remainder = 0

// even numbers go in here so insert the print statement and what everelse



User Avatar

Wiki User

โˆ™ 2013-06-03 17:37:47
This answer is:
User Avatar
Study guides


1 card


See all cards
1 Review

Add your answer:

Earn +20 pts
Q: How do you print only even numbers in an array in java?
Write your answer...
Related questions

Write a java program to print the result in the series?

If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).

Prog to display array element?

Java solutionFortunately, Java has a number of useful functions in the java.util.Arrays class for us.A call to...System.out.println(java.util.Arrays.toString(array));...will print out any array.

How do you write a program in java to read ten numbers and print sum of ten integers?

Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.

What are benefits of array in java?

array example in java

How do you wrte a program to print an array?

You can loop through the array. In Java, this might look like this: for (i = 0; i <= myArray.length(); i++) { System.out.println(myArray[i]); }

Write a java program to find sum of even and odd numbers in given array?

for(int i = 1; i < 100; i+=2) { System.out.println(i); }

How do you write a program to find the sum of n numbers in an array?

In Java: // This program adds all numbers in the array int sum = 0; for (int i = 0; i < myArray.length(); i++) { sum += myArray[i]; }In Java: // This program adds all numbers in the array int sum = 0; for (int i = 0; i < myArray.length(); i++) { sum += myArray[i]; }In Java: // This program adds all numbers in the array int sum = 0; for (int i = 0; i < myArray.length(); i++) { sum += myArray[i]; }In Java: // This program adds all numbers in the array int sum = 0; for (int i = 0; i < myArray.length(); i++) { sum += myArray[i]; }

Write a program to input 10 numbers in an array find and print their sum and average mean?

Open a computer program like Visual Basic, Java, or C#, and then create an object and label it as an array. Input your 10 numbers into the object, then loop through each object in the array to find the sum, average, and mean by writing code in the program.

Sorting an array of numbers in java?

here you will a good example on java sorting algorithm application

Program to print sum of consecutive even and odd numbers in java?

final int limit = 1000000; // Print evens... for(int i = 0; i &lt;= limit; i += 2) { System.out.print(i + " "); } // Print odds... for(int i = 1; i &lt;= limit; i += 2) { System.out.print(i + " "); }

What is an array in java?

Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the array itself will always be an object on the heap, even if the array is declared to hold primitive elements. In other words, there is no such thing as a primitive array, but you can make an array of primitives

Print Maximum of three numbers in java?

system.out.print(Math.max(x, Math.max(y,z)))

How do you write an array that computes the product of the two numbers in java?

You don't need an array for that. Just do the multiplication, for example: result = factor1 * factor2; Or: result = 5 * 8;

What will be the program to print the even numbers between 1 to 10?

Here are two options in Java: // Option 1, increment by 2 at a time: for (int i = 2; i

How do you find sum of all numbers entered in an array with java?

You loop through all the elements in the array. Something like this: sum = 0; for (i = 0; i&lt;= myArray.length()) { sum += myArray[i]; }

How do you swap rows in 2 dimensional array in Java?

[]temp = array[1] array[2]=array[1] array[1]=[]temp

How print even and odd numbers using for loop in reverse order?

In Java: public void printOddsReverseFrom(int from) { // If from is even, decrement it so it's odd if (from % 2 1) from--; for (int i = from; i &gt;= 0; i--) { System.out.println("" + i); } }

Does java array have boundary check?


Can arrays of objects are supported by Java?

Yes, in Java you can create an array of objects.

How does one initialize a byte array in Java?

One can get information about how to initialize a byte array in java on the website stackoverflow dot com. That website can learn one a lot about java.

How to write Short Java program to sort a sequence of numbers 2345 12 1 111 in ascending order?

To sort any array of numbers, use the built in Arrays.sort() methods. int[] array = new int[]{2345, 12, 1, 111}; Arrays.sort(array);

What is variable size array in java?

a variable size array in java simply means a VECTOR. VECTOR is a generic dynamic ARRAY which is variable in size and 'n' number of objects can be created of it.

What is an array in java perspective?

In java,an array is a wrapper class.An array is an object and it gets room in heap.Array can store a collection of data's of same datatype.It can be used to store integers,strings even objects..its collections of data's.Wheather the array stores primitive data,s or objects in it an array s always an object. int numbers[] = new int[10]; this array is of size 10 which can hold 10 int values.This array numbers stores primitive data type but the array number is an object Each item in an array is called an element, and each element is accessed by its numerical index. As shown in the above illustration, numbering begins with 0. The 9th element, for example, would therefore be accessed at index 8.

What do you mean by array in java programming?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array

What Program that will display the even numbers in data structures and algorithms?