-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex006.java
44 lines (37 loc) · 1.4 KB
/
ex006.java
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
package listaexercicios02;
/* Faça um programa para ler e escrever dados de uma turma de 5 alunos.
O programa deve pedir dados como nome, idade e sexo.
O programa deve imprimir os dados do aluno mais velho. Use o laço DO-WHILE. */
import java.util.Scanner;
public class ex006 {
public static void main(String[] args) {
int i = 1, idadeAluno = 0;
String nomeAluno = "", sexoAluno = "";
Scanner input = new Scanner(System.in);
do {
System.out.println("==== DADOS ALUNO ====");
System.out.print("Digite o nome do aluno: ");
String nome = input.next();
System.out.print("Digite a idade do aluno: ");
int idade = input.nextInt();
System.out.print("Digite o sexo do aluno (F/M): ");
String sexo = input.next();
if(i == 1) {
nomeAluno = nome;
idadeAluno = idade;
sexoAluno = sexo;
} else {
if(idade > idadeAluno) {
nomeAluno = nome;
idadeAluno = idade;
sexoAluno = sexo;
}
}
i++;
} while(i <= 5);
System.out.println("Dados do aluno mais velho: ");
System.out.println("Nome: " + nomeAluno);
System.out.println("Idade: " + idadeAluno);
System.out.println("Sexo: " + sexoAluno);
}
}