Anonymous user
Execute Brain****/Java: Difference between revisions
m
Added syntax highlighting and now it looks all cool
m (Optimized a bit on loops) |
m (Added syntax highlighting and now it looks all cool) |
||
Line 10:
More detailed information about the rest of the code can be found in the comments throughout it.<br clear=all>
▲ }
▲ }
▲ }
}
}</java>
▲ public static void jumpBack(StringBuilder code){
▲ //initial count for the bracket we're on
▲ int bracketCnt= 1;
▲ //count brackets until the corresponding [
▲ while(codeIndex >= 0 && bracketCnt != 0){
▲ codeIndex--;
▲ char inst= code.charAt(codeIndex);
▲ if(inst == '[') bracketCnt--;
▲ if(inst == ']') bracketCnt++;
▲ }
▲ //"- 1" to offset the next "codeIndex++".
▲ codeIndex= codeIndex - 1;
▲ public static void jumpForward(StringBuilder code){
▲ //initial count for the bracket we're on
▲ int bracketCnt= 1;
▲ //count brackets until the corresponding ]
▲ while(codeIndex < code.length() && bracketCnt != 0){
▲ codeIndex++;
▲ char inst= code.charAt(codeIndex);
▲ if(inst == ']') bracketCnt--;
▲ if(inst == '[') bracketCnt++;
▲ }
▲ public static void input(ArrayList<Integer> mem, BufferedReader input)
▲ throws IOException{
▲ int val;
▲ //read until something comes in other than return chars
▲ for(val= input.read(); val == 10 || val == 13; val= input.read());
▲ mem.set(pointer, new Integer(val));
|