Last active
August 29, 2015 14:14
-
-
Save SmileyVi/ae3711acdf2d81819714 to your computer and use it in GitHub Desktop.
InstructionSet_Break
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class InstructionSet_Broken { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
String opCode = input.nextLine(); | |
input.close(); | |
String[] codeArgs = opCode.split(" "); | |
long result=0; | |
while (opCode!="END"){ | |
switch (codeArgs[0]) { | |
case "INC": { | |
int operandOne = Integer.parseInt(codeArgs[1]); | |
result = operandOne+1; | |
break; | |
} | |
case "DEC": { | |
int operandOne = Integer.parseInt(codeArgs[1]); | |
result = operandOne-1; | |
break; | |
} | |
case "ADD": { | |
int operandOne = Integer.parseInt(codeArgs[1]); | |
int operandTwo = Integer.parseInt(codeArgs[2]); | |
result = operandOne + operandTwo; | |
break; | |
} | |
case "MLA": { | |
int operandOne = Integer.parseInt(codeArgs[1]); | |
int operandTwo = Integer.parseInt(codeArgs[2]); | |
result = ((long)(operandOne) * (operandTwo)); | |
break; | |
} | |
case "END":{ | |
break; | |
} | |
default: | |
break; | |
} | |
break; | |
} | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment