简体   繁体   English

阅读同一打印行中的内容

[英]Read something in the same print line

I am beginner in JAVA programming and I was wondering about how can I read a number (or character) in same line that I've print a question我是JAVA编程的初学者,我想知道如何在打印问题的同一行中读取数字(或字符)

Example:示例:

 (number to be imputed) : (number to be imputed) : (number to be imputed)

Use print method, it will not change the line and you can enter the number in the same line使用print方式,不会换行,可以在同一行输入数字

import java.util.Scanner;
public class Main {

  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("enter an number : ");
    input.nextInt();
  }
}

does the code below can help?下面的代码有帮助吗?

Scanner s = new Scanner(System.in);
System.out.println(s.nextLine());
s.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM