Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java equivalent of cin (C++)

Tags:

java

c++

how would you code this in Java?

char c;
int n;
cin >> c >> n;

So that I can get this kind of inputs:

X123123
like image 289
Ivan Avatar asked Nov 21 '10 14:11

Ivan


People also ask

What is the equivalent of CIN in Java?

cin does not exist in Java. There is no object cin in Java.

Does Java have cout?

out and cout are the objects representing the stdout stream in Java and C++.

How scanf is used in Java?

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.

What is the scanf equivalent in Java?

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.


1 Answers

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();
like image 159
Matthew Flaschen Avatar answered Oct 03 '22 06:10

Matthew Flaschen