Howdy
Need some simple assistance with Java programming. Can't quite crack it.
I have a text file that has information as below
I need to read in integer 1 and assign it to an integer (cmd) inside my program, and then read in integer 2 and assign it to another integer (data). It should then keep rotating through the text file until it comes to the end.Code:(1,7)(2,0)(4,0)(5,0) (4,0)(2,0)(4,0)(5,0) (1,1)(4,1)(1,25)(4,0) (5,0)(4,0)(5,0)(6,1) (5,0)(5,0)(5,0)(5,0)
The code I currently have in this method is -
If there has been a thread with this kind of assistance in it please direct me to it.Code:public static load() { Scanner scanner = new Scanner(new File(memory.dat)); int reg1 = 0; int reg2 = 0; int cmd = File(:, 1); //I stole this from MATLAB to read in from the file, but it didn't work, though I didn't think it would int data = File(:,2); if (cmd == 1) { reg1 = data; } else if (cmd == 2) { reg1 = reg1 + 1; if (reg1 > 26) { reg1 = 26; } } else if (cmd == 3) { reg1 = reg1 - 1; if (reg1 < 0) { reg1 = 0; } } else if (cmd == 4) { int temp = reg1; reg1 = reg2; reg2 = temp; } else if (cmd == 5) { ascii = reg1 + 65; System.out.println((char)ascii); } }
Thanks
Josh


LinkBack URL
About LinkBacks
Reply With Quote