Thursday, May 11, 2017

Square Root and Cube Root

Problem: Write a java program to print the following multiplication table.


Note: You can use several print and println statements to do this but try something 
different.What about a loop?

/** * @author blankbug * */
public class Square{
    int i;
    public static void main(String[]args){
        Square sq = new Square();
        sq.calculation();
    }


    public void calculation(){
        System.out.printf("%s\t%2s\t%2s\n","Number","Square","Cube");
        System.out.printf("--\t--\t--\n");
        for(int i=1;i<=10;i++){
            System.out.printf("%2d\t%2d\t%2d\n",i,i*i,i*i*i);
        }

    }

}

No comments: