通过读取double获得java.util.InputMismatchException [英] java.util.InputMismatchException by reading a double
本文介绍了通过读取double获得java.util.InputMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试读取0.6时,出现了java.util.InputMismatchException异常,这是代码的一部分.如您所见,我尝试为练习表重新实现SkipList.
I got the an java.util.InputMismatchException when I try to read 0.6 here is a part of the code. As you can see i try to reimplement a SkipList for a exercise sheet.
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double f = scan.nextDouble();
impl_with_errors list = new impl_with_errors(f);
int n = scan.nextInt();
public class impl_with_errors {
public static double chance;
public Node list0;
public Node list1;
public Node list2;
public Node list3;
/**
* the constructor of the skiplist
* @param p the chance that an element shall be in a higher list
*/
public impl_with_errors(double p) {
chance = p;
list0 = null;
list1 = null;
list2 = null;
list3 = null;
}
推荐答案
使用逗号作为小数点分隔符,而不是点. 0,6
有效
Use a comma as decimal sperator, not a dot. 0,6
works
使用DecimalFormat df = new DecimalFormat("#,#");
这篇关于通过读取double获得java.util.InputMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文