Menu
Topics Index
...
`

Print multiplication table


If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to print the multiplication table of the given number. Use System.out.println or System.out.print for printing.

Input (Integer) Output to be printed (Spaces before and after 'x' and '=' are also important in the output)
4 4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
5 5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50



class MultiplicationTable
{
    public static void main(String s[])
    {
        printMultiplicationTable(5);

    }


    public static void printMultiplicationTable(int number)
    {
    }

}
Topic: for Loop In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

for(int i=1;i<=10;i++)
{
int c=n*i;
printf("%d*%d=%d",n,i,c);
}
for 20 integers
we can have for(int i=1;i<=20;i++)
{
int c=n*i;
printf("%d*%d=%d",n,i,c);
}

Posted by Sai Veerendra    2014-11-25 05:57:37


Hello all, please do not include the complete code here. Please only write the logic/algorithm/flow so that new programmers can read this text and write the programs.

Posted by Merit Campus    2014-11-25 06:22:21


for(int j=1;j<=10;j++){
System.out.println(input+"x"+i+input*i) ;
}

Posted by Dereje Goshu    2014-11-25 06:38:32


Iterate over the for loop from 1 to 10; for every iteration in the loop, multiply the current loop counter with the input number.And print the format shown in the output onto the console using system.out.println

Posted by Shashanka Mogaliraju    2014-11-25 06:59:15


Here we can use for loop, the loop control variable can be initialized to 1, then use condition i<=10, satisfying this condition the input element can be multiplied with the current loop counter, then it prints the result by incrementing each time untill the condition become false. In print method (input + "x" + i + input * i ) can be used to print the output in required format.

Posted by Sai Ram    2014-11-25 17:37:14


here we just need 1 loop for iteration,and the loop needs to iterate exactly 10 times.so we can select any loop condition to execute this condition. 1st for loop here u need to initialize one local variable with 1,give condition for 10 time iteration,thn incremnt. thn inside for loop print (input arg number+" "+" X"+" "+local variable value+" "+"="+" "+(multiplication of number and iteration value). bcz spacing between "x"and "=" are important

Posted by Maheshwari Natarajan    2014-11-25 19:11:57


This dose is now closed and the winners are Sai Ram,  for 'First Correct Comment', Shashanka Mogaliraju, Maheshwari Natarajan,  for 'Second Correct Comment'. The 'lucky liker' is Deepika Deepu. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-11-27 07:39:46


© meritcampus 2019

All Rights Reserved.

Open In App