1
I’m having trouble with this code, I’m starting in programming, this is just an activity for practice. I do not understand why when executing the code the field 'Campus' does not allow the entry of information. It already goes to the field 'Registration'
Campus: Registration (Numbers only):
Remember, it’s just an initial practice of the programming discipline, nothing too far-fetched.
package classescanner;
import java.util.Scanner;
/**
* @author magnolia
*/
public class ClasseScanner {
public static void main(String[] args) {
String nome, sexo, matricula;
String campus;
int ano;
double nota1, nota2, media;
Scanner entrada = new Scanner (System.in);
String escola = "IFRN CAMPUS ";
System.out.println("------------------------------");
System.out.println("DIGITE AS INFORMAÇÕES DO ALUNO");
System.out.println("------------------------------");
System.out.print("Nome completo: ");
nome = entrada.nextLine();
System.out.print("Sexo: ");
sexo = entrada.nextLine();
System.out.print("Ano de nascimento (yyyy): ");
ano = entrada.nextInt();
System.out.print("Campus: ");
campus = entrada.nextLine();
System.out.print("Matrícula (Apenas números): ");
matricula = entrada.nextLine();
System.out.print("Nota 1: ");
nota1 = entrada.nextDouble();
System.out.print("Nota 2: ");
nota2 = entrada.nextDouble();
media = (nota1 + nota2) / 2;
System.out.println("--------------");
System.out.println("SITUAÇÃO FINAL");
System.out.println("--------------");
System.out.println(escola.concat(campus).toUpperCase());
System.out.println("Matrícula nº: " + matricula);
System.out.println("Aluno(a): " + nome.toUpperCase() + " - Sexo: " + sexo.substring(0,1).toUpperCase() + " - Nascido(a) em: " + ano);
if (media >= 60){
System.out.println("Status: APROVADO(A)");
}
else {
System.out.println("Status: REPROVADO(A)");
}
}
}
Instead of
nextLine()
use onlynext()
– Sorack
Corrected code and explanation according to comments and other suggested topic.
– Sorack