I would like to know how to use Scanner
in java
to simulate cin
and cout
of c ++
I would like to know how to use Scanner
in java
to simulate cin
and cout
of c ++
Using Scanner
you can capture data entry using the methods below, which are the most common:
Scanner s = new Scanner(System.in);
s.nextInt();
s.nextDouble();
s.nextFloat();
s.next(); //captura como string mas se o trecho tiver espaço, ignora o que
//estiver após o espaço. Não move o scanner pra linha seguinte
s.nextLine();// captura como string uma linha inteira e para após uma quebra
//de linha, move o scanner para a linha seguinte
You only have to be careful when using captures of primitive types with String captures, because of the line break .
And for data output, java has System.out.println()
which displays information by inserting a line break, and System.out.print()
does the same thing, but without the line break.