?
Solved

Tips to improve this program

Posted on 2009-07-05
2
Medium Priority
?
176 Views
Last Modified: 2013-11-23
The output of this program is correct and as expected. It is actually a metric of multiplication.

Please advice me regarding code practices, maintability, readability, efficiency etc

package cattledrive;

public class Times {
      public static void main(String[] args) {
            for(int i = 0; i < 11; i++){
                  for(int j = 0; j < 11; j++){
                        if(i == 0){
                              if(j == 0){
                                    System.out.format("%4s" , " ");
                                    continue;
                              }
                              else{
                                    System.out.format("%4d" , j - 1);
                                    continue;
                              }
                        }
                        else{
                              if(j == 0){
                                    System.out.format("%4d", i - 1);
                                    continue;
                              }
                        }
                        
                     System.out.format("%4d" , (i - 1)*(j - 1));
                  }
                  System.out.println();
            }
      }

}
0
Comment
Question by:SunScreenCert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 800 total points
ID: 24783045
With such a simple program, there is not much you can do to improve readability or maintainability except perhaps:

1) Add some comments to describe what you are doing
2) Use more descriptive variable names than i and j

0
 
LVL 20

Accepted Solution

by:
a_b earned 1200 total points
ID: 24783113
At best you can remove the else clauses out of the program because they are redundant, and follows the guidelines provided by mrjoltcola
public static void main (String... args)
    {
        for (int i = 0; i < 11; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (i == 0)
                {
                    if (j == 0)
                    {
                        System.out.format("%4s", " ");
                        continue;
                    }
                    System.out.format("%4d", j - 1);
                    continue;
                }
                if (j == 0)
                {
                    System.out.format("%4d", i - 1);
                    continue;
                }
 
                System.out.format("%4d", (i - 1) * (j - 1));
            }
            System.out.println();
        }
    }

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question