asked 132k views
1 vote
Modify the provided code file to create a workout tracking program that lets the user enter (from the console) the distance they ran each day of the week. Store each value into an array of doubles named distances

1 Answer

5 votes

Answer:

  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6. double distances [] = new double[7];
  7. for(int i=0; i < distances.length; i++){
  8. System.out.print("Input running distance for day " + (i+1) + ": ");
  9. distances[i] = input.nextDouble();
  10. }
  11. System.out.println(Arrays.toString(distances));
  12. }
  13. }

Step-by-step explanation:

The solution code is written in Java.

Firstly, create a Scanner object to get user input for running distance (Line 6). Next, declare a distances array and set the array size to 7 because we intend to use this array to hold running distance for 7 days per week.

Next, use the for loop that run for 7 times to repeatedly prompt user to input running distance for each day and store each value to the array distances (Line 9 -12).

At last, display the array to console terminal (Line 14).

answered
User MuiBienCarlota
by
8.8k points