- Where Developers Learn, Share, & Build Careers
I am trying to create a CE-lo program in simple, simple Java. I'm just learning. However, when I get my immediate w (I have simplified it for testing) it just always loses, I can not know why it also shows the correct figures, but when it compares it it fails .
public class ceeLo {public static zero main (string [] args) {scanner scan = new scanner (System.in); Int [] die = new int [3]; Integer answer; Boolean roll = true; Boolean quiffed; Boolean Immediate W; Boolean Immediate L; Do {System.out.println ("Roll Dice?"); Answer = scan.nextInt (); If (answer == 0) roll = wrong; Else {int i; (I = 0; i & lt; die.length; i ++) for {die [i] = rollin (); Println (diceTxt (die [i])); } Clifed = (Eligible (Die)); System.out.println ("Qualified =" + Qualified); InstantW = (easy (dead)); System.out.println ("instant win =" + instant w); }} While (roll); } // Generate Random Numbers for Roll Stable Constants Roll Roll () {Random Rand = New Random (); Int die = rand.nextInt (6); Return to die; } // Check whether the pair qualify with the public stable boolean qualification (int [] die) {boolean qualification; // pair qualification rolls (die [0] == die [1] || die [0] == die [2] = die [1] == die [2]) Qualified = true ; Other worthy = false; Return qualification; } // Check that instant win public stable boolean easyW (int [] die) {boolean instantW; // show the contents of die [x] for the system. Out.println (die [0] + "" + die [1] + "" + die [2]); If (die [0] & gt; 2 & amp; amp; and; [1]> 2 & amp; amp; will die [2] & gt; 2) instantW = true; other; InstantW = Wrong; Immediate return; }}
delete after the semi-colon; It should be just that
I think the reason is,
instantW = false; is not considered as a separate statement as part of the second block, which is why it is always being handed over to false and returning liars. It is always better to use {} to define the block, though they are single liners. This is my preference.
As suggested by Greg Hagil, using the single statement instantW = die [0]> 2 & amp; Amp; Die [1] & gt; 2 & amp; Amp; Die [2] & gt; 2; If better than / Others.
Comments
Post a Comment