Hello I am learning Java so I am getting the following error an I do not understand why I am getting the error because I when I change the datatype to Int and then run the code, the code runs properly without any errors so I get a bit confused on what is really happening
Error Message
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextFloat(Scanner.java:2496)
at SecondProject/com.SecondProject.Fundamentals.workerPay(Fundamentals.java:22)
at SecondProject/com.SecondProject.Fundamentals.main(Fundamentals.java:8)
Code below
package com.SecondProject;
import java.util.*;
public class Fundamentals {
public static void main(String[] args) {
workerPay();
}
public static void workerPay() {
float hours;
float rates;
float total_pay;
float extra_hours;
float tax;
Scanner sc = new Scanner(System.in);
System.out.println("Enter in your hours of work: ");
hours = sc.nextFloat();
System.out.println(hours);
}
}