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)
- import java.util.Scanner;
- public class Question10 {
- public static void main(String[] args) {
- Scanner scnr = new Scanner(System.in);
- final double SPEED_OF_SOUND = 761.207; // Miles/hour (sea level)
- final double SECONDS_PER_HOUR = 3600.0; // Secs/hour
- final double secondsBetween = 0.0;
- double timeInHours;
- double distInMiles;
- System.out.println("Enter seconds between");
- System.out.print("lightning strike and thunder: ");
- secondsBetween = scnr.nextDouble();
- timeInHours = secondsBetween / SECONDS_PER_HOUR;
- distInMiles = SPEED_OF_SOUND * timeInHours;
- System.out.println("Lightning strike was approximately");
- System.out.println(distInMiles + " miles away.");
- }
- }
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
Get step-by-step solutions from verified subject matter experts
