I want to learn how to enter numbers from the keyboard. For example, let it be necessary to enter the coordinates of two points. The program, the text of which is below, makes it an awkward way. Here's what I don't like:

  1. After the program starts, the cursor in the console is not active. It is necessary to activate through the mouse.
  2. After entering the first pair of numbers and pressing the input, the line "Enter point2's x-, y-coordinates:" appears and the cursor is in front of the first character (ie, before 'E'), and not at the end of this line.

How to fix it, especially the 2nd moment? Or is it an Eclipse environment feature?

package dzmitrok; import javafx.geometry.*; import java.util.Scanner; public class TwoLineOnPlane { public static void main(String[] args) { Scanner myinput = new Scanner(System.in); System.out.print("Enter point1's x-, y-coordinates: "); double x1 = myinput.nextDouble(); double y1 = myinput.nextDouble(); System.out.print("Enter point2's x-, y-coordinates: "); double x2 = myinput.nextDouble(); double y2 = myinput.nextDouble(); Point2D p1 = new Point2D(x1, y1); Point2D p2 = new Point2D(x2, y2); System.out.println("Point1: " + p1.toString()); System.out.println("Point2: " + p2.toString()); } } 

    2 answers 2

    What is your operating system, and especially the terminal emulator?
    I just checked, everything works.

    Concerning the first question. If you are working in a program, you can only have one program at a time, respectively, when you start a terminal / console, then the focus remains on IDE (if you, of course, do not compile everything from the terminal), therefore, when you start, you remain in your IDE, and in order to enter the data, you must, respectively, click on the terminal to get the focus. And it depends not on your program, but on the operation of the window system.

    On account of the second question. Everything works for me, most likely, the terminal emulator does not work correctly for you, as far as I understand, after entering the first word, your cursor does not appear after ":", but at the beginning of this line, that is, before the phrase asking to enter data?
    Maybe you simply entered incorrect data, and after the error the cursor moved. You do not have verification on the correctness of the input.

    Here, if anything, my code, or rather your copied - everything works:

     import javafx.geometry.Point2D; import java.util.Scanner; /** * Created by crosp on 12/19/14. */ public class TwoLineOnPlane { public static void main(String[] args) { Scanner myinput = new Scanner(System.in); System.out.print("Enter point1's x-, y-coordinates: "); double x1 = myinput.nextDouble(); double y1 = myinput.nextDouble(); System.out.print("Enter point2's x-, y-coordinates: "); double x2 = myinput.nextDouble(); double y2 = myinput.nextDouble(); Point2D p1 = new Point2D(x1, y1); Point2D p2 = new Point2D(x2, y2); System.out.println("Point1: " + p1.toString()); System.out.println("Point2: " + p2.toString()); } } 
    • OS: Windows 7 "Home Premium", rus, service pack1 IDE: Eclipse Luna c android SDK (i.e. the development environment that Google offered for android programming before Android Studio 1.0) Yes, you understood the cursor after entering The first pair of numbers and clicking on the input is at the beginning of the line "Enter point2's x-, y-coordinates:" instead of being after "*:" I do not know where to look at the emulator type. - bhjnbnnn
    • By the way, maybe this is due to the presence of the warning "Build path specifies the execution environment of JavaSE-1.7. There are no JREs?" - bhjnbnnn
    • Quite, I honestly do not know, there is no way to check. There is no Windows at all. Most likely, these are due to a curved terminal on Windows. - CROSP

    Yes, these are unpleasant features of the Eclipse console. Run the application from the command line, and everything will work fine. Run in your project directory

     java -cp bin dzmitrok.TwoLineOnPlane