public static void readMark(){
Scanner sc = new Scanner(System.in);
float mark;
System.out.print("Enter mark : ");
mark = sc.nextDouble();
System.out.println("Mark entered is " + mark);
}
In this case, the compiler will state the error of "Type mismatch: Cannot convert double to float."
I don't understand.
From the java documentation, "Scans the next token of the input as a double... then the token is converted into a double value" .
So shouldn't the float value of the variable 'mark' be converted to a double value when it is scanned and not the other way round ?

New Topic/Question
Reply



MultiQuote




|