Java - Print number table

Description

Print number table

Demo

public class HitTheTarget {
    public static void main(String[] args) {
        int theTarget = 10;

        for (int i = 1; i <= 20; i++){
            for (int j = 1; j <= 20; j++){
                if ((i + j) == theTarget) {
                    // result via add found
                    System.out.printf("%d + %d = %d\n", i, j, i + j);
                } else if ((i - j) == theTarget) {
                    // result via subtract found
                    System.out.printf("%d - %d = %d\n", i, j, i - j);
                }//from   w w  w  .j a  v  a 2  s.c o m
            }
        }
    }
}

Related Topic