• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanner moving onto next line  RSS feed

 
Anthony Noack
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm taking a programming class at my school and have an assignment to create a bank balance calculator.
I have no problem doing so and have already completed the math however I want to fix my output.

Currently I have:


However when I enter a letter for the string "type" and press enter it skips to the next line. I want it to move onto the amount of transaction input on the same line but below "Amount Of Transaction"
I want my output to look like this:


If there is a way to accomplish this I'm all ears (I left out the the math and other decleration statements because they are fine all that's incorrect is how it is displayed)
 
Campbell Ritchie
Marshal
Posts: 55770
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can instruct the terminal cursor to move to a particular location. If you use nextLine, it reads from the current location to the next time the Enter key is pressed. You can try
System.out.print("             ");
or similar, but you will be one line down and cannot come back.

Delay printing the output until after you have got all the input. Beware of nextLine after nextSomethingElse.

And welcome to the Ranch
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use System.out.println you advance to the next line, when you use System.out.print you will stay on the same line.

The problem you have is that you are going to do a read and need to output information, in the old days of using terminal I/O you had 2 options: either write a screen scraper and editor or just advance the line and print what you want to show.

When you do console based apps in Java, it is much easier to do the advance to the next line and use combinations of print and println to get the look you want for the new line.
 
Anthony Noack
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats unfortunate but thank you for the response', I will probsbly create a 4th colum for input it will just be on multiple lines
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!