I’m just now trying to learn Java and my question is how I read something that the user types?
When I learned C++ the first thing I learned was cin/cout but in java I’ve seen tutorials that talk about GUI before reading user input.
To put it simply, how do I make this program in java:
int main()
{
int foo;
cin >> foo;
cout << foo;
return 0;
}
something like this:
public class foo {
public static void main(String[] args)
{
int foo;
READ FROM IN-BUFFER;
System.out.println(foo);
}
You need to use a Scanner:
Here, the Scanner reads input from System.in (the keyboard), then assigns the value of the input to foo. If the input is not an int, an exception will occur.