Como puedo usar el scanner? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Como puedo usar el scanner?

21st Jun 2019, 1:30 AM
Junior13
Junior13 - avatar
2 Respuestas
+ 3
At first you need to import the scanner class: import java.util.Scanner; In your code: Scanner scan = new Scanner(System.in); //the scanner waits now for user input int i = scan.nextInt(); double d = scan.nextDouble(); String str = scan.next(); String str = scan.nextLine(); long l = scan.nextLong(); and so on... https://www.sololearn.com/learn/Java/2220/?ref=app
21st Jun 2019, 10:00 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Lo importas: Import java.util.Scanner; Creas un objeto tipo scanner: Scanner 'nombre q quieras del objeto' = new Scanner(System.in); Y lo usas cuando lo necesites: Supongamos q tu objeto scanner se llama scan, scan.nextInt(); para almacenar enteros, scan.nextLine(); para cadenas de texto (String's) System.out.print ("escribe tu nomre: "); String nombre = scan.nextLine(); si en vez de llamarse tu objeto scan, se llamara in, seria in.nextInt(); etc
21st Jun 2019, 2:12 PM
Matias
Matias - avatar