How to clean an int variable in java?

-1

I'm developing a program that has a menu that if I type 1 register a course and if I type 2 register a student both ifs are working type if I type 1 register a course close the console open again type 2 and type a student happens everything normally but if I type 1 register the course the menu reappears and I type 2 to register a student msm I typing 2 he enters again in the course if follows the code

public static void main(String[] args) {

tela.menu();

if (opc == 1){

for(posc=0;posc<10;posc++){

//seta o nome do curso
System.out.print("Digite o nome do curso: ");
nomecurso = entrada.next();
sala.setNome(nomecurso);
nomescurso[posc] = nomecurso;

//seta o codigo do curso
System.out.print("Digite o codigo do curso: ");
codigocurso = entrada.nextInt();
sala.setCodigo(codigocurso);
codigoscurso[posc] = codigocurso;

System.out.print("\n");
posc++;
tela.menu();

}

}else if(opc == 2){

for(posa=0;posa<10;posa++){

//seta o nome do aluno 
System.out.print("Digite o nome do aluno: ");
nomealuno = entrada.next();
pessoa.setNome(nomealuno);
nomesaluno[posa] = nomealuno;

//seta a matricula do aluno 
System.out.print("Digite a matricula do aluno: ");
matricula = entrada.nextInt();
pessoa.setMatricula(matricula);
matriculas[posa] = matricula;

//seta o cpf do aluno 
System.out.print("Digite o cpf do aluno: ");
cpf = entrada.next();
pessoa.setCpf(cpf);
cpfs[posa] = cpf;

//liga um aluno a um curso 
System.out.print("Digite o codigo do curso cursado pelo aluno: ");
alunocursa = entrada.nextInt();
alunoscursam[posa] = alunocursa;    
}

System.out.print("\n");
posa++;
tela.menu(); 
    
asked by anonymous 12.03.2017 / 17:42

1 answer

0

Do you want to clear an integer variable from memory?

To do this directly is not possible ... java has Garbage Collector, this causes it to take memory out of itself when it is no longer used.

You can set it to -1 to identify anywhere in the code that it is empty if needed.

    
12.03.2017 / 22:20