java - 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;
}
}
非常感谢阅读我,对不起我的英语。
解决方案
您可以在控制台中做的一件事通常看起来不错:打印出默认值
> Enter your name (jonny):
如果用户不输入任何内容而只是点击Enter
,请使用默认值。
如果用户确实输入了某些内容,请使用它。
推荐阅读
- typescript - 在 Ionic 4 中向构造函数添加参数
- c - SDL_CreateRenderer() 与 SDL_CreateSoftwareRenderer()
- matplotlib - 如何删除 seaborn.pairplot() 中的标记边缘?
- c# - 如何在 C#/Unity 中访问我预定义的结构化对象中的其他元素?
- javascript - 如果键有多个单词,如何从 Firebase Realtime DB 查询数据?
- javascript - 如何在父子组件之间使用回调函数
- sql - 根据开始和结束数字生成行?
- python - 如果“key”中有空格,Python s3 copy_from 会失败。如何搜索文件内容,然后使用 python 打印存储在 S3 中的文件名
- r - 使用 Windows 批处理自动化使用 ODBC 的 R 脚本
- nginx - Nginx 配置只匹配基本路径,否则返回 404。为什么?