how would you code this in Java?
char c;
int n;
cin >> c >> n;
So that I can get this kind of inputs:
X123123
cin does not exist in Java. There is no object cin in Java.
out and cout are the objects representing the stdout stream in Java and C++.
It is used to scan the next token of the input as a byte. Advances this scanner past the current line. It is used to scan the next token of the input into a boolean value. It is used to scan the next token of the input as a long.
There is not a pure scanf replacement in standard Java, but you could use a java. util. Scanner for the same problems you would use scanf to solve.
You can use Scanner
with System.in
. E.g.
Scanner s = new Scanner(System.in);
char c = s.findInLine(".").charAt(0);
int n = s.nextInt();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With