Java Programming : Multiplication of a number

Example

Input
5
Output
5 10 15 20 25

Required to Know

Use of Variables, Use of different operators like assignment or arithmetic operators, Use of methods like System. out. print(), and use of for loop, and Use of Data types

Steps

This program determines what multiplication of the number will be based on the input of the user. Here's a breakdown of how it works:

  • Imports the Scanner class from java.util package

  • Defines a public class called Mavenproject1

  • Defines a main method that takes an array of Strings as input

  • Creates a new Scanner object called sc with the argument System.in

  • Take the range as input from the user.

  • Use for loop. Now inside the print statement do the multiplication and make sure you provide some space between them.

Program

import java.util.Scanner; 
public class Mavenproject1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); 
        int i, n; 
        n = sc.nextInt();
        for(i=1;i<=n;i++){
            System.out.print(n*i + " ");
        }
    }
}