0

Description

Get two inputs  num1 and num2, compute the product of num1 and num2 without using  * operator
Input:
5 6
Output:
30

Solution

import java.util.*;
class MulTab
 {
     public static void main(String args[])
     {
          int ans=0,i,table,numberoftimes;
          System.out.println("Enter The Number Of Times And Table value");
          Scanner sc=new Scanner(System.in);
          table=sc.nextInt();
          numberoftimes=sc.nextInt();
          for(i=1;i<=numberoftimes;i++)
            {
			ans+=table;
            }
		System.out.println(ans);
      }
}

Explanation

Instruction(s) inside the for block{} are executed repeatedly till  the second expression (i<=table)is true.

Here i is initialized to 1 and incremented by 1 for each iteration, instructions inside the for block are executed unless i becomes greater than m. so value of i (1,2,3,...m)will be add num2 with m time and printed in table format.
Ramesh P Natarajan

Author - Ramesh P Natarajan

Learner, Professor, Technology Trainer, Software Developer and Content Marketer, very much passionate in the field of Software Application Development, Machine Learning and Search Engine Optimization.

Write to: admin@decodeschool.com





Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution