Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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 如何在字符串1之后接受长输入_Java_Input - Fatal编程技术网

Java 如何在字符串1之后接受长输入

Java 如何在字符串1之后接受长输入,java,input,Java,Input,此代码段不允许我将输入带到pincode变量。我发现有三件事需要更改 去掉所有那些没有给变量赋值的多余的sc.next()行。你没有理由想在这些点上读一个额外的标记 考虑使用sc.nextLine()而不是sc.next()来读取字符串,这样,如果输入中有空格,它们就会成为字符串的一部分 阅读解释调用sc.nextLong()后可能遇到的问题的答案,以及如何处理该问题 仔细阅读next()和nexline()方法的javadocs。然后看看你的代码。重复,直到你找到答案!!这是一个调试问题。。

此代码段不允许我将输入带到pincode变量。

我发现有三件事需要更改

  • 去掉所有那些没有给变量赋值的多余的
    sc.next()
    行。你没有理由想在这些点上读一个额外的标记
  • 考虑使用
    sc.nextLine()
    而不是
    sc.next()
    来读取
    字符串
    ,这样,如果输入中有空格,它们就会成为
    字符串
    的一部分
  • 阅读解释调用
    sc.nextLong()
    后可能遇到的问题的答案,以及如何处理该问题

仔细阅读
next()
nexline()
方法的javadocs。然后看看你的代码。重复,直到你找到答案!!这是一个调试问题。。。你需要自己解决这个问题。否则,你将无法在考试或面试中做到这一点。
Scanner sc = new Scanner(System.in);
    System.out.println("Enter the details given below.");
    System.out.println("Name:");name=sc.next();
    sc.next();

    System.out.println("Phone/mobile number:+91 ");phone_num=sc.nextLong();
    System.out.println("Home Address:");address=sc.next();
    sc.next();
    System.out.println("Pincode:");pincode=sc.nextLong();
    System.out.println("E-mail address:");e_mail=sc.next();
    sc.next();