Read something in the same print line

Tags:



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)

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();
  }
}


Source: stackoverflow