How can I write the command to input external data in Java?

0

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);
    
asked by anonymous 01.08.2017 / 01:04

1 answer

1

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.     

01.08.2017 / 03:44