java - Having trouble with Boolean. Making a test if an integer is greater/less than another... How to output saying that he/she is right/wrong? -
import java.util.random; import java.util.scanner; public class boolean { public static void main(string[] args){ string zz; scanner keyboard = new scanner(system.in); random r1 = new random(); random r2 = new random(); random greatless = new random(); int x = r1.nextint(10) + 1; int y = r2.nextint(10) + 1; int z = greatless.nextint(2) + 1; if (z == 2) { zz = "<"; } else { zz = ">"; } system.out.println("is " + x + " " + zz + " " + y + "? (y/n)"); string ans = keyboard.nextline(); } }
i don't know write after keyboard input. want tell them if they're right or wrong using boolean class... want if else after. guess like...
if (ans.equalsignorecase("y") { -insert code- } else { - insert code- }
the logic is:
- if x < y, , z == 2 , ans "y", correct
- if x < y, , z == 2 , ans "n", incorrect
- if x < y, , z == 1 , ans "y", incorrect
etc.
try accomplish.
Comments
Post a Comment