Multiplication Table..

package solutions.java;

/**
 * Created by rchouhan on 11/1/14.
 *
 * For Zero iterations
 * O(N) < Olog(N)
 *
 * replace N with 0; and log(0) = 1
 *
 * For N > 0
 *
 * O(N) < Olog(N) < O(Nlog(N)) < O(N + N) (also O(2N)) (or also O(N^2)) < O(N^N)
 */


public class MultiplicationTable {

    public static void main(String[] args){
        multiplicationTable(3);
        multiplicationTableUntil(3);
    }

    // Time Complexity is O(N)
    static void multiplicationTable(int i){

        for(int j=0; j<=10; j++){
            System.out.println(i +" X " + j +" = " + i*j);
        }
    }

    // Time Complexity is O(N^2)
    static void multiplicationTableUntil(int input){
        for(int i=1; i<= input; i++){
            System.out.println("\nMultiplication Table for " + i + "\n");
            for(int j=0; j<=10; j++){
                System.out.println(i +" X " + j +" = " + i*j);
            }
         }
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s