in this code i have logical error
its give me wrong output
import java.util.Scanner;
public class OneFile {
static final int MAX = 100;
static final int READ = 10, WRITE = 11, LOAD = 20, STORE = 21;
static final int ADD = 30, SUBTRACT = 31, MULTIPLY = 32, DIVIDE = 33;
static final int BRANCH = 40, BRANCHNEG = 41, BRANCHZERO = 42, HALT = 43, SENTIAL=-99999;
int memory[] ,accumulator, operand, operationCode, instructionCounter, instructionRegister;
public void execution(){
Scanner input=new Scanner(System.in);
memory = new int[MAX];
accumulator = 0;
operand = 0;
operationCode = 0;
instructionCounter = 0;
instructionRegister =0;
int index =0;
//zeros all memory locations
for (int i = 0; i < MAX; i++)
memory[i] = 0;
System.out.println("*** Welcome to Simpletron! ***\n" +
"*** Please enter your program one instruction ***\n" +
"*** (or data word) at a time into the input ***\n" +
"*** text field. I will display the location ***\n" +
"*** number and a question mark (?). You then ***\n" +
"*** type the word for that location. Press the ***\n" +
"*** Done button to stop entering your program ***\n");
while( true )
{
System.out.printf("%02d ", index);
memory[index] = input.nextInt();
if( memory[index] == -99999 )
break;
else
index++;
System.out.print("\n");
}
System.out.print("*** Program loading completed ***\n" +
"*** Program execution begins ***\n" );
instructionRegister = memory[instructionCounter];
operationCode = instructionRegister / 100;
operand = instructionRegister % 100;
switch( operationCode )
{
case READ:
System.out.print( "Enter integer value : " );
memory[index++] = input.nextInt();
instructionCounter++;
break;
case WRITE:
System.out.println("value for operand " + operand + " = " + memory[operand]);
instructionCounter++;
break;
case LOAD:
accumulator = memory[operand];
instructionCounter++;
break;
case STORE:
memory[operand] = accumulator;
instructionCounter++;
break;
case ADD:
accumulator += memory[operand];
instructionCounter++;
break;
case SUBTRACT:
accumulator -= memory[operand];
instructionCounter++;
break;
case MULTIPLY:
accumulator *= memory[operand];
instructionCounter++;
break;
case DIVIDE:
accumulator /= memory[operand];
instructionCounter++;
break;
case BRANCH:
instructionCounter = operand;
break;
case BRANCHNEG:
if (accumulator < 0)
instructionCounter = operand;
else
instructionCounter++;
break;
case BRANCHZERO:
if (accumulator == 0)
instructionCounter = operand;
else
instructionCounter++;
break;
case HALT:
System.out.println("***Simpletron execution terminated***");
break;
}
System.out. println( "\n*************END SIMPLETRON EXECUTION*************\n" );
int i;
System.out. println( "REGISTERS:\n"+"accumulator = "+accumulator+"\n instructioncounter ="+
instructionCounter+"\ninstructionregister= "+instructionRegister+
"\noperationcode ="+operationCode+"\noperand ="+operand );
System.out. println( "\n\nMEMORY:\n " );
for ( i = 0; i <= 9; i++ ) {
System.out. printf( "%5d ", i );
}
for ( i = 0; i <MAX; i++ ) {
if ( i % 10 == 0 ) {
System.out. printf( "\n%2d ", i );
}
System.out. printf( "%+05d ", memory[ i ] );
}
System.out. printf( "\n" );
}
public static void main(String [] args){
OneFile obj= new OneFile();
obj.execution();
}
}