I made a calculator in C++ and i'm trying to recreate it mirror-like in Java.
There were 2 double variables(
op = '+'
cout << a << op << b << "=" << a+b << endl;
Scanner Scin = new Scanner(System.in);
a = Scin.nextDouble();
op = Scin.next().charAt(0);
b = Scin.nextDouble();
You can't read in multiple variables at once using
Scanner, you will have to read them in one at a time. However, there is a nice way to allow the inputs to occur without hitting enter each time or inputting a space: set a different delimiter! The default delimiter is whitespace (which includes newlines), but you could also set it to the word boundary
\b from regex.
Scanner in = new Scanner(System.in).useDelimiter("\\b|\\s+");
Now you can read in
12+2 and it will split up the
next calls where you want them, or you can continue to hit enter, or you can put spaces between the values. Your choice :D
To restore the delimiter to normal afterwards, use