Question: Arrays Exercise PART 1: This has been completed Create an array of doubles that has space enough for five separate values. Write a while loop

Arrays Exercise

PART 1: This has been completed

Create an array of doubles that has space enough for five separate values.

Write a while loop that will set the value of the first 5 elements of your array to the numbers 1 through 5.

Then write a for loop that will print out the first 5 elements of your array. Use the provided Arrays_With_Loops.java file as a starter file.

PART 2: This has NOT been completed

Building off the previous exercise, you should add some more code to the end of your program, which will ask the user for a number, and then use a loop to go through the array, and see if any of the values in the array match the number that the user typed in.

If there is a match, you should print out a message telling the user that their number was found in the array.

The message should also tell the user which index location the number was found at.

Here's the file I have so far with the first part completed:

import java.util.*;

public class Arrays_With_Loops extends Object

{

public static void main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

// First: Create an array

int i = 0; // array starts from 0

double [] array = new double[5];

// Second: Use a while loop to set the array elements' values

while(i < array.length)

{

array[i] = i+1;

i++;

}

// Third: Use a for loop to print out the array

for(double val : array)

{System.out.println(val);}

//Second Part of the assignment: User asking

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!