Pattern 14

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

1. You are given a number n.
2. You've to write code to print it's multiplication table up to 10 in format given below.
Input Format
A number x
Output Format
pat141
Question Video
Constraints
1 <= n <= 10
Sample Input
3
Sample Output
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30


  • Editorial

    "If at first, you do not succeed; call it version 1.0"

    Question:

    1. You are given a number x.

    2. You have to write code to print it is multiplication table up to 10 in the format given below.

    Input format:

    A number x

    Output format:

    x * 1 = x

    x * 2 = 2x

    x * 3 = 3x

    ........

    x * 10 = 10x

    Constraints:

    1 <= x <= 10

    Solution Approach:

    We have to print a multiplication table of the given number 'x'. We run a loop until 10. Saving results of multiplication for print command convenience and write the print command according to the output format.

    Code:

    import java.util.*;
                                    public class Main{
                                        public static void main(String[] args)
                                        {
                                            Scanner scn = new Scanner(System.in);
                                            int x = scn.nextInt();
                                            for(int i=1;i<=10;i++)
                                            {
                                                int val = x*i;
                                                System.out.println(x + " * " + i + " = " + val );
                                            }
                                    
                                        }
                                    }

    java false

  • Asked in Companies
  • Related Topics






Video Solution

Code Solution

Run
 
Run
Id Name