I have a basic college project and one of the requirements of exercise is to remove the last value from an array of integers. I am not able to do with the last value being removed without using an ArrayList, another specification would be to not use an ArrayList and use the Pop function for such an action, I would need some help since the only method I found would be to replace the last one value by 0 and copy this array to a new array, but I think it would not be the most efficient, follow the code with the other functions of the code:
public class Pilha {
Scanner in = new Scanner(System.in);
private int top;
private int[] element = new int[10];
Pilha(){
}
public int Push(){
System.out.println("Insira os numeros desejado");
for(int j = 10; j > 0; j-- ){
top = in.nextInt();
element[j-1] = top;
}
return top;
}
public int Pop(){
return 0;
}
public void Show(){
for(int i = 10; i > 0; i--){
System.out.println(element[i-1]);
}
}
public void Menu(){
System.out.println("Digite o que quer fazer");
System.out.println("Digite 1 para inserir na pilha");
System.out.println("Digite 2 para remover o ultimo elemento");
System.out.println("Digite 3 para mostrar a pilha");
}
public void Menu2(){
System.out.println("Digite o que quer fazer");
System.out.println("Digite 2 para mostrar a pilha");
System.out.println("Digite 3 para remover o ultimo elemento");
}