Java - Use loops to do simple math

Objective

In this challenge, we are going to use loops to do some simple math.

Task

Given an integer, n, print its first 10 multiples.

Each multiple n x i (where 1 = i = 10) should be printed on a new line in the form: n x i = result.

Input Format

A single integer, n.

Output Format

Print 10 lines of output; each line i (where 1 = i = 10) contains the result of n x i in the form:

n x i = result.

Demo

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        int n = 2;
        /*from w ww .  ja v  a 2s  .co  m*/
        int sum;
        
        for(int i = 1; i <= 10; i++){
            sum = n * i;
            System.out.println(n + " x " + i + " = " + sum);
        }
    }
}

Related Topic