Created
January 28, 2019 17:29
-
-
Save parzibyte/7d88198b7c1e831ed6762683192fa0db to your computer and use it in GitHub Desktop.
Leer datos del teclado con Java created by parzibyte - https://repl.it/@parzibyte/Leer-datos-del-teclado-con-Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Leer datos que el usuario introduce a través del teclado | |
usando Scanner y algunos métodos | |
@author parzibyte | |
*/ | |
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner escaner = new Scanner(System.in); | |
// Leer una cadena | |
System.out.println("Hola. Dime tu nombre: "); | |
String nombre = escaner.nextLine(); | |
// Leer un entero | |
System.out.println("Dime tu edad: "); | |
int edad = escaner.nextInt(); | |
// Leer un flotante | |
System.out.println("Dime tu peso: "); | |
float peso = escaner.nextFloat(); | |
System.out.println("Te llamas " + nombre + ", tienes " + edad + " años y tu peso es de " + peso + " kilogramos"); | |
// Al final y por buenas prácticas cerramos el escaner | |
escaner.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment