File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
src/main/java/com/example Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,30 @@ public class AppScanner {
7
7
//OBS: o scanner precisa do import:
8
8
// import java.util.Scanner;
9
9
10
+ // scanner.nextLine() -> STRING
11
+ // scanner.nextInt()
12
+ // scanner.nextDouble()
13
+
14
+
10
15
public static void main (String [] args ) {
11
16
Scanner scanner = new Scanner (System .in );
17
+
18
+ // o scanner.NEXTLINE() retorna uma STRING
12
19
System .out .print ("Digite o nome: " );
13
20
String nome = scanner .nextLine ();
14
21
15
22
System .out .print ("Digite a idade: " );
16
23
Integer idade = scanner .nextInt ();
17
24
18
- System .out .printf ("%s tem %d anos" , nome , idade );
19
25
26
+ scanner .nextLine (); // OBSSS: ESSE scanner nextline extra é pra PEGAR O ENTER que vem DEPOIS DE UM NÚMERO!
27
+ // quando pega um nextInt e depois um nextLine, da esse probleminha, ai usa esse extra pra captar esse ENTER SOLTO.
28
+
29
+ System .out .print ("Digite o sexo: " );
30
+ // obs: para conseguir um CHAR (pois não tem nextchar): usa-se o CHARAT(0)
31
+ String sexoString = scanner .nextLine ();
32
+ char sexo = sexoString .charAt (0 );
33
+
34
+ System .out .printf ("O %s tem %d anos e é %c " , nome , idade , sexo );
20
35
}
21
36
}
You can’t perform that action at this time.
0 commit comments