How to clean an int variable in java?

Asked

Viewed 1,234 times

-1

I am developing a program that has a menu that if I type 1 register a course and if I type 2 enrollment a student both ifs are working type if I type 1 register a course close the console open again type 2 and cadster a student occurs all normally but if I type 1 register the course the menu reappears and I type 2 to register a student msm 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(); 
  • 1

    Where is the screen metodo.()?

  • 1

    And this code is incomplete, some keys are not being closed.

  • I copied and put only the main , but you understood my problem ?

1 answer

0

You want to clear an integer number variable from memory?

Doing this directly is not possible... Java has Garbage Collector, this makes it take out of memory alone when it is no longer used.

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

  • I already did that it continues with the first value I always type , like if I enter the if of the 1 in the first execution and the second try to enter the if of the 2 it enters again in the if of one and see and versa, I want to enter an if and zerala for in the next run enter the if you want

Browser other questions tagged

You are not signed in. Login or sign up in order to post.