本文介绍了获取用户输入时出错(JAVA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我刚刚学会了在执行过程中使用Scanner类来获取用户输入。然而,在练习这个时,我面临着一个问题。 这是我的代码 import java.util.Scanner; public class a { public static void main() {扫描仪b = 新扫描仪(System.in); System.out.println( 输入整数); int c = b.nextInt(); System.out.println( 输入字符串); String d = b.nextLine(); System.out.println(); System.out.println( 您输入的整数是 + a); System.out.println( 您输入的字符串是 + b); } } 我的尝试: 在运行程序时,它正在输入整数并相应地打印,但它不是要求String的输入并直接打印空白字符串。 但是,如果我要完全消除整数的输入并打印它,那么我的程序正确地输入字符串并打印。为什么不能两者一起完成? 有人可以帮忙吗?!解决方案 Hi, I've just learned to use Scanner class to take user input during execution. However, on practicing this, I'm facing an issue.Here is my codeimport java.util.Scanner;public class a{public static void main(){ Scanner b = new Scanner(System.in); System.out.println("Enter the integer"); int c = b.nextInt(); System.out.println("Enter the string"); String d = b.nextLine(); System.out.println(); System.out.println(" The integer you entered is" + a); System.out.println(" The string you entered is "+b); }}What I have tried:On running the program, it's taking input of integer and printing accordingly but it isn't asking for the input for String and printing a blank string directly.However, if i were to completely eliminate the taking input from integer and printing it, then my program correctly takes input of String and prints. Why can't the both be done together?Can someone please help?! 解决方案 这篇关于获取用户输入时出错(JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 12:52