-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClase Java 13.java
More file actions
75 lines (40 loc) · 2.33 KB
/
Clase Java 13.java
File metadata and controls
75 lines (40 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//--------------------------------------------------------------|
//CONTENIDO: Sentencia scanner
//--------------------------------------------------------------|
package clase.java.pkg13;
//-----------------------|
import java.util.Scanner; //Para utilizar el scanner es necesario importar esta clase
//-----------------------|
public class ClaseJava13 {
//----------------------------------------------------------------------------------------------------------------|
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//----------------------------------------------------------------------------------------------------------------|
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.printf("Introduce tu nombre: ");
String nombre = sc.nextLine(); //Lee lo que escriba el usuario.
//"nextLine()" se utiliza para leer Strings
System.out.println("\nHola " + nombre + ", como estas?\n");
//------------------------------------------------------------------------------------|
//Leer enteros
System.out.printf("Introduce tu edad: ");
int edad = sc.nextInt();
System.out.println("\nTienes "+ edad + " anos.\n" );
//------------------------------------------------------------------------------------|
//Leer float
System.out.printf("Introduce tu peso: ");
float peso = sc.nextFloat();
System.out.println("\nPesas "+ peso + " kg.\n" );
//------------------------------------------------------------------------------------|
//Leer double
System.out.printf("Introduce tu altura: ");
double altura = sc.nextDouble();
System.out.println("\nAltura "+ altura + " m.\n" );
//------------------------------------------------------------------------------------|
//Otros
//"nextBoolean()" <-- Lee booleanos
//"nextByte()" <-- Lee bytes
//"nextLong()" <-- Lee datos tipo long
//"nextShort()" <-- Lee datos tipo short
}
}