1

I'm using Scanner objects to get user inputs, but in the console after the enter key is pressed after the input, a new line is created. I just want it to jump to the next input area and not make a new line. Below is the output and after that is what happens after I press enter.

Please enter the number of residents in your house: 
Please enter the area of the living space in square feet: 
Please enter the Total monthly cost of internet:  






Please enter the number of residents in your house: 5

Please enter the area of the living space in square feet: 
Please enter the Total monthly cost of internet: 

While the program does read the input, I have to manually use the arrow keys to enter the next one. Any help is appreciated. The actual code is below:

 import java.util.Scanner;
//prints the House text-image
public class House{
 public static void main(String[] args){
  float monthlyInternet;

  int numResidents, sqFeet;

  Scanner sc = new Scanner(System.in);

  System.out.println("Please enter the number of residents in your house: ");

  System.out.println("Please enter the area of the living space in square feet: ");

  System.out.println("Please enter the Total monthly cost of internet: ");

  numResidents = sc.nextInt();

  sqFeet = sc.nextInt();

  monthlyInternet = sc.nextFloat();




  System.out.println("   . _ _ _ _ _ .");

System.out.println("  / \\ _ _ _ _ _ \\");

  System.out.println("  | |   0   0   |");

  System.out.println("  |_| _ _ H _ _ |");


  }//end main
 }//end class
  • sorry this is not clear what you are asking. Please show some code to illustrate your problem – Scary Wombat Jan 16 '17 at 00:50
  • In a console program (where you'd use a Scanner object) you don't have the sort of fine control that you are looking for. I am not sure if Java has libraries like curses in Unix C that allow you to jump to particular areas on a terminal. – David Choweller Jan 16 '17 at 00:53
  • Unless you want to invest in using some kind of curses library, this isn't going to be possible with Java's command line support – MadProgrammer Jan 16 '17 at 00:53
  • Really? It seems like such a basic fix that I'm surprised there isn't a solution. Thanks anyways. – Jodhanveer Ghangheri Jan 16 '17 at 00:57
  • @JodhanveerGhangheri this is a classic [XYProblem](http://xyproblem.info/). Instead of first printing and afterwards reading input, just print one line, read the corresponding input and repeat until you've read all input you need. –  Jan 16 '17 at 01:36
  • There is a solution, but it's in a library. You can't include everything in the base language, especially system-dependent features like console output, which depend on which terminal emulation is used, and so on. Anyway, most end-users are not going to be using console applications. The web, and GUIs are where it's at, nowadays. – David Choweller Jan 16 '17 at 01:37
  • This is similar to [this](http://stackoverflow.com/questions/1001335/java-gotoxyx-y-for-console-applications) SO post. – DevilsHnd - 退職した Jan 16 '17 at 02:05

0 Answers0