I have the following code:
import javax.swing.JOptionPane;
public class Excercise613 {
public static int askInt(String prompt) {
String s = JOptionPane.showInputDialog(prompt);
Double d = Double.parseDouble(s);
return d >= 0 ? (int) d : (int) (d - 1);
}
}
When I compile this, I get an error message at the bottom of the screen that says "non-convertible types". required: int; found: java.lang.Double "And then it highlights the code fragment (int) d".
What am I doing wrong here? Why doesn't casting work?
source
share