If you want to do some math, write it. . .

If you want to do some math, write it. . .

 

/**
	 * Generate addition and subtraction math problems within 20
	 */
	private static void generateMental() {
		Random ra = new Random();
		int count = 0;
		
		while (count < 100) {
			int firstSymbol = ra.nextInt (2)% 2;
			String fs = "";
			int secondSymbol = ra.nextInt (2) % 2;
			String ss = "";
			
			int first = ra.nextInt(20);
			int second = ra.nextInt(20);
			int third = ra.nextInt(20);
			
			if (first == 0 || second == 0 || third == 0) {
				continue;
			}
			
			int result = 0;
			if (firstSymbol == 1) {
				fs = " + ";
				result = first + second;
				if (result > 20) {
					continue;
				}
			} else {
				fs = " - ";
				result = first - second;
				if (result < 0) {
					continue;
				}
			}
			
			if (secondSymbol == 1) {
				ss = " + ";
				result = result + third;
			} else {
				ss = " - ";
				result = result - third;
			}
			
			if (result > 0 && result < 20 ) {
				System.out.println(first + fs + second + ss + third + " = ");
				count ++;
			}
			
			if (count % 25 == 0) {
				System.out.println("========" + count / 25 + "=========");
			}
		}
	}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530345&siteId=291194637