Question: in java The below code produces the error message displayed below the code. 1. Explain what the error message is trying to tell you about

in java

The below code produces the error message displayed below the code.

1. Explain what the error message is trying to tell you about what is wrong with the code. (4 points)

2. Which line number does the Java compiler think the problem might be on? (2 points)

3. How might you fix this problem? (4 points)

 
  1. import java.util.Scanner;
  2. public class Question10 {
  3. public static void main(String[] args) {
  4. Scanner scnr = new Scanner(System.in);
  5. final double SPEED_OF_SOUND = 761.207; // Miles/hour (sea level)
  6. final double SECONDS_PER_HOUR = 3600.0; // Secs/hour
  7. final double secondsBetween = 0.0;
  8. double timeInHours;
  9. double distInMiles;
  10. System.out.println("Enter seconds between");
  11. System.out.print("lightning strike and thunder: ");
  12. secondsBetween = scnr.nextDouble();
  13. timeInHours = secondsBetween / SECONDS_PER_HOUR;
  14. distInMiles = SPEED_OF_SOUND * timeInHours;
  15. System.out.println("Lightning strike was approximately");
  16. System.out.println(distInMiles + " miles away.");
  17. }
  18. }

C:\Users\...\Question10.java:14: error: cannot assign a value to final variable secondsBetween

secondsBetween = scnr.nextDouble();

1 error

BUILD FAILED (total time: 0 seconds)

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!