I migrated from C to Java and would like to know which command allows the user to enter external data and how that command would be in code.
In language with C
use the code below:
scanf(%tipo_da_variavel, &nome_da_variavel);
I migrated from C to Java and would like to know which command allows the user to enter external data and how that command would be in code.
In language with C
use the code below:
scanf(%tipo_da_variavel, &nome_da_variavel);
scanf()
in C is equivalent to Scanner
in Java. Here is an example:
Scanner scanner = new Scanner(System.in);
// valores do tipo inteiros
int n = scanner.nextInt();
// valores do tipo strings
String s = scanner.nextLine();
// valores do tipo double
double d = scanner.nextDouble();
See more details and examples in the Scanner class documentation.