Simple I/O Question...well could be simple for you?
Okay guys so say i wanted to take in code from a scanner object for an example
i do something like this
Code :
System.out.println("EXPRESSION MIN_X MAX_X MIN_Y MAX_Y DELTA_X WIDTH HEIGHT");
Where i want the user to enter in something as the following "((x^2)-50)" -10 +10 -100 +100 0.01 800 500
now would there be anyway of optimizing my code so that i dont have to keep doing something like this:
Code :
Scanner inScan = new Scanner (System.in);
System.out.println("Enter Expression:");
String expression = inScan.nextLine();
System.out.println("Enter MIN_X");
int Min_X = inScan.nextInt();
and just simply extract code from one scanner call?
Do you understand what i mean?
Any help is appreciated!
Re: Simple I/O Question...well could be simple for you?
What's the difference? The user ends up with the same amount of typing. If it's all on one line, they have to separate the fields with horizontal whitespace (spaces), if it's question-by-question, they have to type vertical whitespace (enter key). With the enter key, they also get to read reminders of what they should be typing. You can also ask users to enter the data all on one line and user getInt etc... which may be what you're currently doing.
There is no golden bullet for this problem because there's no way of returning multiple separate data from a Java method, and no pass-by-address, so you can't provide a format string (like C's scanf) and expect a method to assign variable of various types based on the content of a string. Scanner's get<Type>() methods are the closest you'll get.