Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions