Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 双扫描不';不要用试抓_Java_Try Catch_Java.util.scanner - Fatal编程技术网

Java 双扫描不';不要用试抓

Java 双扫描不';不要用试抓,java,try-catch,java.util.scanner,Java,Try Catch,Java.util.scanner,这是我的密码: public static void setPriority(List<Performer> listperformer) { Scanner localsc = new Scanner(System.in); if(listperformer.isEmpty() == true) { System.out.println("- empty -"); return; } else { System.out.println("

这是我的密码:

public static void setPriority(List<Performer> listperformer)
 {
  Scanner localsc = new Scanner(System.in);
  if(listperformer.isEmpty() == true)
  {
   System.out.println("- empty -");
   return;
  }
  else
  {
   System.out.println("ID:");
   int id = localsc.nextInt();
   if(listperformer.size() < id || id < 0)
   {
    System.out.println("Invalid input!");
    return;
   }
   else
   {
    double priority = 1.0;
    try{
     System.out.println("Priority:");
     priority = localsc.nextDouble();
     listperformer.get(id).setPriority(priority);

    }catch(InputMismatchException e)
    {
     System.err.println("Invalid input!");
    }

   }
  }
publicstaticvoidsetpriority(列表列表执行者)
{
Scanner localsc=新扫描仪(System.in);
if(listperformer.isEmpty()==true)
{
System.out.println(“-empty-”);
返回;
}
其他的
{
System.out.println(“ID:”);
int id=localsc.nextInt();
if(listperformer.size()

当我想扫描像2,7这样的东西时,它可以工作,但是如果我把逗号改为点,它会导致“无效输入!”输出。

检查是否需要使用我们的语言环境

Scanner localsc = new Scanner(System.in);
localsc.useLocale(Locale.US);

首先,我没有它,这只是为了尝试,为什么这段代码不接受点你的语言环境是什么?逗号和点在任何语言环境中都不是同一个意思。好的,但是通常double类型的变量总是带点的,或者我错了吗?在Java中是的,因为它是由美国人开发的,但是当读取输入时,语言环境决定了什么是double
是小数点,因此如果
2,7
有效,则您的区域设置很可能是
是小数点。@FarazDurrani您不应该是,但他应该感谢您@pragnanikinereded再等3分钟;-)upvote目前为止不起作用--明天再试一次!