some random person’s war 2009.10.23

my nine year old nephew is teaching himself how to code, on his own, without help.

i worked with him to take his very first effort and convert it to java – here it is.

public class SomeRandonPersonsWar {
	public static void main(String[] args) {
		int i = 130;
		int e = 20;

		while (i > 30) {
			System.out.println("Kill unit "
				+ (i/2)
				+ " and unit "
				+ (i+1));
			i = i - (e + 5);
			e =  i / 2;
		}

		System.out.println("You need "
			+ i
			+ " more bullets and "
			+ (i + e)
			+ " more units.");

		while (i < 50) {
			System.out.println("Unit "
				+ i
				+ " has capitulated.");
			i += 5;
		}
	}
}

and here is the result:

Kill unit 52 and unit 106
Kill unit 24 and unit 49
You need 19 more bullets and 28 more units.
Unit 19 has capitulated.
Unit 24 has capitulated.
Unit 29 has capitulated.
Unit 34 has capitulated.
Unit 39 has capitulated.
Unit 44 has capitulated.
Unit 49 has capitulated.

Leave a Reply

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha


« | »