Skip to content

Instantly share code, notes, and snippets.

@SmileyVi
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SmileyVi/ae3711acdf2d81819714 to your computer and use it in GitHub Desktop.
Save SmileyVi/ae3711acdf2d81819714 to your computer and use it in GitHub Desktop.
InstructionSet_Break
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