大佬教程收集整理的这篇文章主要介绍了接下来如何在扫描仪之间打印文本?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 Java 的初学者,在使用 ScAnner 进行多个输入时遇到问题,其中包含打印文本。以下代码不会打印文本,而只会接受输入。请帮忙!
private static voID createNewMochaDrink() {
ScAnner scan = new ScAnner(@R_502_3813@);
System.out.println("Please SELEct which Mocha you would like");
System.out.println("1. White Chocolate Mocha\n2. Dark Chocolate Mocha\n3. Peppermint Mocha");
int choice = scan.nexTint();
System.out.print("Enter Milk amount: ");
double milkamount = scan.nextDouble();
System.out.print("Enter Espresso Shot: ");
double espressoShot = scan.nextDouble();
scan.nextline();
System.out.print("Enter Chocolate Type: ");
String chocoType = scan.nextline();
首先我会切换到 System.out.println(...)
而不是 print
。它添加了一个回车符,使您的打印语句更易于阅读。
其次,如果你想做的是打印用户刚刚输入的内容,那么你需要添加:
private static void createNewMochaDrink() {
ScAnner scan = new ScAnner(System.in);
System.out.println("Please SELEct which Mocha you would like");
System.out.println("1. White Chocolate Mocha\n2. Dark Chocolate Mocha\n3. Peppermint Mocha");
int choice = scan.nexTint();
System.out.print("Enter Milk amount: ");
double milkamount = scan.nextDouble();
System.out.print("Enter Espresso Shot: ");
double espressoShot = scan.nextDouble();
scan.nextLine();
System.out.print("Enter Chocolate Type: ");
String chocoType = scan.nextLine();
System.out.println("You SELEcted: "+choice+" and "+
milkamount+" milk and "+espressoShot+" espresso shots and "+
chocoType+" chocolate type");
}
这样就可以了。
这是Eclipse控制台中的结果
以上是大佬教程为你收集整理的接下来如何在扫描仪之间打印文本?全部内容,希望文章能够帮你解决接下来如何在扫描仪之间打印文本?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。