63 066
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #3481 in Java | JSP | JSF for Y mukundareddy

Question #3481
(4) Write a program to store n elements in an array and retrieve the even numbers from that array.
Expert's answer
import java.util.Random;

public class Task11
{
public static void main(String[] args)
{
& Random generator = new Random(100);

& // The length of the array
& int n = generator.nextInt(20) + 10;

& // Generating the elements of the array
& int[] numbers = new int[n];
& System.out.println("The elements of the generated array: ");
& for (int i = 0; i < n; i++)
& {
& numbers[i] = generator.nextInt(1000);
& System.out.print(numbers[i]);
& if (i < n - 1)
& System.out.print(", ");
& }

& // Outputing the even elements of the array
& System.out.println("\n\nThe even elements of the array: ");
& for (int number : numbers)
& if (number % 2 == 0)
& System.out.print(number + ", ");
& System.out.println("\b\b");
&
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions