首页 > 解决方案 > java扫描仪上的占位符

问题描述

在控制台中,如何在扫描仪上放置占位符?

让我给你看一个例子

public class main {
  string name;
  public void main(){
   name = " default ";
  }

 public void modif(){
  Scanner sc = new Scanner(System.in);
  String str = sc.nextLine(); // At this moment i want in the console the current value of name. The user can delete it, and replace it with the new name. Or just modify it
  this.name=str;
 }
}

非常感谢阅读我,对不起我的英语。

标签: java

解决方案


您可以在控制台中做的一件事通常看起来不错:打印出默认值

> Enter your name (jonny):

如果用户不输入任何内容而只是点击Enter,请使用默认值。

如果用户确实输入了某些内容,请使用它。


推荐阅读