Ivan
Ivan

Reputation: 83

Java equivalent of cin (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

Upvotes: 8

Views: 52168

Answers (1)

Matthew Flaschen
Matthew Flaschen

Reputation: 284796

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();

Upvotes: 22

Related Questions