Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:42:21+00:00 2026-06-06T17:42:21+00:00

public class MultiplicationTable { public static void main (String[]a){ int[] x; x = new

  • 0
public class MultiplicationTable {
public static void main (String[]a){

    int[] x;
    x = new int[10];
    int i;
    int n=0;

    for (i=0;i<x.length;i++){
        n++;
        x[i]=n;
        System.out.print(x[i] + " ");
    }

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[0] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[1] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[2] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[3] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[4] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[5] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[6] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[7] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[8] * x[i] + " ");

    System.out.println();
    for (i=0;i<x.length;i++)            
        System.out.print(x[9] * x[i] + " ");


}
}

This is a program that will display a Multiplication Table like this:

1 2 3 4 5 6 7 8 9 10

1 2 3 4 5 6 7 8 9 10

2 4 6 8 10 12 14 16 18 20

3 6 9 12 15 18 21 24 27 30

4 8 12 16 20 24 28 32 36 40

5 10 15 20 25 30 35 40 45 50

6 12 18 24 30 36 42 48 54 60

7 14 21 28 35 42 49 56 63 70

8 16 24 32 40 48 56 64 72 80

9 18 27 36 45 54 63 72 81 90

10 20 30 40 50 60 70 80 90 100

===============================================================

It is running and correct but I want it to look like this one:

01 02 03 04 05 06 07 08 09 10

01 02 03 04 05 06 07 08 09 10

02 04 06 08 10 12 14 16 18 20

03 06 09 12 15 18 21 24 27 30

04 08 12 16 20 24 28 32 36 40

05 10 15 20 25 30 35 40 45 50

06 12 18 24 30 36 42 48 54 60

07 14 21 28 35 42 49 56 63 70

08 16 24 32 40 48 56 64 72 80

09 18 27 36 45 54 63 72 81 90

10 20 30 40 50 60 70 80 90 100

===============================================

Is there any way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:42:25+00:00Added an answer on June 6, 2026 at 5:42 pm

    Yes you can! You can use String.format to add zero padding to your output.

    Example:

    String.format("%05d", 2) would produce 00002.

    Some improvement on the current code:

    I’m not sure why you intend to store the numbers inside an array (for practice purpose maybe), but that is not necessary as it goes from 1 to 10 anyway. Though if you want to do that, you don’t need both i and n.

    for (i=0; i<x.length; i++){
        x[i] = i+1;
        System.out.print(x[i] + " ");
    }
    

    Secondly, I’m sure you realize that you have a lot of duplicate code, and it’s quite sequential. You can do that using 2 nested for loops, instead of having 10 single loops:

    for (int row = 1; row <= 10; row++) {
        for (int col = 1; col <= 10; col++)
            System.out.print(String.format("%03d", row * col));
        System.out.println();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Test1{ public static void main(String[] args){ StringBuffer s=new StringBuffer(abcde); reverseString(s); System.out.println(s); }
public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x);
public class Divers { public static void main(String args[]){ String format = |%1$-10s|%2$-10s|%3$-20s|\n; System.out.format(format,
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class Employee { public static void main(String[] args) { int j=3; staples[] stemp
public class InterruptedInput { public static void main(String[] args) { InputThread th=new InputThread(); //worker
public class Test{ public void Test(String name){}; public static void main() { Test t=new
public class Main { public static void main (String args[]) { int nums[]= {2,
public class Start { public static void main(String[] args) { JFrame j = new
public class TextFileExtractor{ public static String[] fileExtractor(String[] s){ StringBuilder sb=new StringBuilder(); for(int i=0;i<=s.length;i++){ if(s[i].endsWith(.txt)){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.