Skip to content
Advertisement

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

Example:

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

Advertisement

Answer

Use print method, it will not change the line and you can enter the number in the same line

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();
  }
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement