if statement - Trying to implement a score system while using if/else. [JAVA] -
I am just starting in Java and if I use any other statements in a score system I am trying to either increase increment or subtraction according to correct or incorrect answers. If the text found in the text text file is false and if the disturbance user matches the mail then the program should be increased. Right now, the program will display incorrect "1" and "1" if true, no matter how often it goes through the loop. It should change the value of the result but it keeps resetting to "0" I have already tried but I believe that I had an issue with scope. If someone can help, I would be very grateful.
package typetrain; Import java.util. *; Import java.io * *; Import javax.swing. *; / ** * * @author Haf * / Public Square Game1 {Public Zero Game () {JOptionPane.showMessageDialog ("Zero," Please answer in the correct line of the text. \ N "+" Each line of text will give you a point grant "+" \ N Wrong answers will reach the point that happens "); String filename = "test.txt"; String line; Arrialist list = new Arrayist (); Try {BufferedReader input = new BufferedReader (New FileReader (fileName)); If (! Input.ready ()) {new IOException (); } While ((line = input. Readline ()) = null) {aList.add (line); } Input.close (); } Hold (IOException e) {System.out.println (e); } Int sz = aList.size (); For (int i = 0; i & lt; sz; i ++) {int result = 0; String Corrections = aList.get (i) .toString (); String userpanzer = joppenpan.showinputdialog (empty, "copy this line of text! \ N" + aList.get (i) .toString ()); If (correct answers.equals (userAnswer)) {JOptionPane.showMessageDialog (tap, "right!"); Results ++; } And if (right answer couple (user reply)) {JOptionPane.showMessageDialog (tap, "wrong!"); result--; } YojanaPen Show message dialog (faucet, result); } }}
You just need to move your result for code = 0; Otherwise in the line before its loop, it will be reset to 0 each time.
Comments
Post a Comment