java - Why does my printed equation keep printing the same number? -
i trying make adding game randomly generated numbers added not random though assigned them random each time. please. i'm still working on project stuck on part. code far:
package addgame; import java.util.random; import java.util.scanner; public class add { private static scanner console; public static void main(string[] args) { system.out.println( "we going play adding game. type answer."); equation(); } public static void answer(scanner console) { } public static void equation() { int tries = 0; while (tries == 0) { random rand = new random(); int nums = rand.nextint(25) + 6; int totalnums = rand.nextint(4) + 1; int sumans = 0; (int = 1; <= totalnums + 1; i++) { system.out.print(nums + "+ "); sumans += nums; } system.out.print("= "); console = new scanner(system.in); int ans = console.nextint(); system.out.println(sumans); } } }
you must put randomizer inside for-loop
:
private static scanner console; public static void main(string[] args) { system.out.println( "we going play adding game. type answer."); equation(); } public static void answer(scanner console) { } public static void equation() { int tries = 0; while (tries == 0) { random rand = new random(); int nums = 0; int totalnums = rand.nextint(4) + 1; int sumans = 0; (int = 1; <= totalnums + 1; i++) { nums = rand.nextint(25) + 6; //changed system.out.print(nums + "+ "); sumans += nums; } system.out.print("= "); console = new scanner(system.in); int ans = console.nextint(); system.out.println(sumans); } } }
Comments
Post a Comment