Java Program To Print Table

The program below is the answer to Liang’s Introduction To Java Programming (9th Edition) Chapter 1 Exercise 1.4.

Click here to see other solutions to Introduction to Java Programming.

7 Comments

  1. Can l solve it like that:
    for(int i 1;i<=4;i++)
    S.o.p(math.pow(i,1);
    S.o.p(math.pow(i,2);
    S.o.p(math.pow(i,3),

  2. Can l solve it like that:
    for(int i 1;i<=4;i++)
    S.o.p(math.pow(i,1);
    S.o.p(math.pow(i,2);
    S.o.p(math.pow(i,3),

  3. Hello @CanhDuc KCO, I know you can use loops to solve the exercise but the aim is to use techniques that have been taught up to that exercise chapter in the textbook (in this case Exercise 1.4 of the 9th Edition).

    P.S. Though your code is correct, it doesn't produce the required output. Your code prints the table on a single vertical line. A better code can be found here: Java Program to Print Table Using Loop.

    Thanks for your contribution.

  4. public static void main(String[] args) {
    for (int i = 0; i < 3; i++) {
    System.out.println("a^"+(i+1));
    for (int j = 0; j < 4; j++) {
    if(i==0) System.out.println(j+1);
    if(i==1) System.out.println((j+1)*(j+1));
    if(i==2) System.out.println((j+1)*(j+1)*(j+1));
    }

    }

  5. Hi Malik, thanks for the comment. I try to update the blog as often as possible. Just add the site to your bookmarks so you can easily revisit it.

  6. I highly appreciate this post. It’s hard to be good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information?

Write A Comment