0

I'm working on a program that takes the date from users as such:

Scanner scanint;
System.out.println("Date(DD/MM/YYYY): ");
scanint = new Scanner(System.in);//I'm actually using try-catch here
int day = scanint.nextInt();
System.out.print("/");
int month = scanint.nextInt();
System.out.print("/");
int year = scanint.nextInt();

What I want the program to display is this:

Date(DD/MM/YYYY): (User inputs day)/(user inputs month)/(user inputs year)

What the program is actually displaying is this:

Date(DD/MM/YYYY): (user inputs day)

/(user inputs month)

/(user inputs year)

I realize that the issue here is that when you press the enter key after using Scanner class the program returns to the next line. I'm thinking about storing it inside one string, that way i could remove the line break by using substring method. But if i do that, how will i be able to take user input, print out that string and keep everything on the same line all at once?

1 Answers1

0

The easy way is clean all console output:

Runtime.getRuntime().exec("cls");

Examples: Java: Clear the console

Community
  • 1
  • 1
Krzysiek
  • 615
  • 8
  • 19
  • well, it's not working! please elaborate further, like where do i put it and what does it do? i'm new to programming! – user3787456 Jun 29 '14 at 19:01