So I am new to java and was trying to learn about simple data structure and wrote a program in bluej to pop in a stack. However after compiling and executing the program the output is different each time.
The code is as follows:
class popstack
{
static int arr[]={31,45,64,100};
public static void main()
{
int top=0;
int i=top;
System.out.println(arr[top]);
while(i<3){
arr[i]=arr[i+1];
arr[i+1]=0;
i=i+1;
}
for(int j=0;j<4;j++)
{
System.out.print(arr[j]+",");
}
}
}
Expected Output: 1st execution :
31
45,64,100,0,
2nd execution :
31
45,64,100,0,
Output: 1st execution :
31
45,64,100,0,
2nd execution :
45
64,100,0,0,
Shouldn't the outputs be same since i am always initializing the array?
EDIT: The issue was fixed when i added the paramter string[] args to the main method.