Answer to Question #206951 in Java | JSP | JSF for Bengazi

Question #206951
Write a program that prompts the user for the size; and prints the multiplication table of that size. For example,
Enter the size of the table: 5
*|12345 ================= 1|12345 2 | 2 4 6 8 10 3|3 6 91215 4|4 8121620 5 | 5 10 15 20 25
1
Expert's answer
2021-06-15T01:28:51-0400


package multiplicationtable;
import java.util.Scanner;




/**
 *
 * @author Student
 */
public class MultiplicationTable{
   
   


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       System.out.println("Enter a number to display multiplication table\n");
        Scanner input = new Scanner(System.in);
      // System.out.println("Enter the starting
      int n = input.nextInt();
    
       System.out.print("---------------------------------\n");
      for(int i = 1; i<=n; i++){
          System.out.print(i +"\t");
      }
      System.out.print("\n");
       System.out.print("---------------------------------\n");
      int a = n + 1;
     for(int i=1; i<=a; i++){
        
         for(int j=1; j<=a; j++){
             // System.out.print(j +"\n");
           
             if(j == a ){
                 
                 System.out.print("\t");
                 System.out.print("\n");
             }
             else{
                System.out.print((j * i)+"\t");  
             }
            
           // System.out.print(" ");
         }
     }
       
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS