Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I cant figure out part 2 of this, i have 1 done Using a working version of question 1, expand your program with the following:

I cant figure out part 2 of this, i have 1 done

Using a working version of question 1, expand your program with the following:

Create the following method: public static double[] loadArray(Scanner sc)

i. The above method takes a scanner as an argument and returns a double array.

ii. Move the code which performed these actions from the main method and change your variables as needed.

iii. Re-initialize numArray to call the new method.

Create another method: public static int countEven(double[] a)

i. This method takes an double array as an argument and returns an integer

ii. Move the code which performed these actions from the main method and change your variables as needed.

iii. Re-initialize evenCount to call the new method.

Note: your output will remain the same as question 1

my code for part 1

package Exam1; import java.util.*; class Exam1 { public static void main(String[] args) { int evenCount=0; Scanner ss = new Scanner(System.in); double arr[]=new double[5]; for(int i=0;i<5;i++){ System.out.print("Enter a number into the array: "); arr[i]=ss.nextDouble(); } for(double i:arr){ if(i%2==0){ evenCount++; } } System.out.println("Number of even numbers in the array: "+evenCount); } }student submitted image, transcription available below

1. Write a Java application which performs the following: Creates a double array of size 5 Using a for loop, prompt the user for 5 doubles Using an enhanced for loop iterate through the array and keep track of how many elements are EVEN NUMBERS (Control Structure?) using a counter variable: int evenCount Display output as shown below The file name and class should be named Exam1_LastName1.java (35\%). \begin{tabular}{|l|l|} Output - AC01_130_Exam1 (run) \#2 \\ \hline W & run: \\ Enter a number (Whole or decima1) to store in the array: 1 \\ Enter a number (Whole or decimal) to store in the array: 2 \\ Enter a number (Whole or decimal) to store in the array: 3 \\ Enter a number (Whole or decimal) to store in the array: 4 \\ Enter a number (Whole or decimal) to store in the array: 5 \\ The array contains: [1.0,2.0,3.0,4.0,5.0] \\ 2 of these values are even numbers. \end{tabular} Once you have completed question one, use the file > save as feature to create question 2 2. Using a working version of question 1, expand your program with the following: > Create the following method: public static double[] loadArray(Scanner sc) i. The above method takes a scanner as an argument and returns a double array. ii. Move the code which performed these actions from the main method and change your variables as needed. iii. Re-initialize numArray to call the new method. Create another method: public static int countEven(double[] a) i. This method takes an double array as an argument and returns an integer ii. Move the code which performed these actions from the main method and change your variables as needed. iii. Re-initialize evenCount to call the new method. Note: your output will remain the same as question 1 The file name and class should be named Exam1_LastName2.java (35\%)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago