Q:

Java program to multiply two numbers using plus (+) operator

belongs to collection: Java Basic Programs

0

Java program to multiply two numbers using plus (+) operator

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will read two integer numbers and calculate the multiplication of input numbers using the "+" operator.

Program/Source Code:

The source code to multiply two numbers using the plus "+" operator is given below. The given program is compiled and executed successfully.

// Java program to multiply two numbers 
// using plus "+" operator

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    int num1 = 0;
    int num2 = 0;
    int mul = 0;

    Scanner myObj = new Scanner(System.in);

    System.out.printf("Enter first number: ");
    num1 = myObj.nextInt();

    System.out.printf("Enter second number: ");
    num2 = myObj.nextInt();

    for (int loop = 1; loop <= num2; loop++)
      mul += num1;

    System.out.printf("Multiplication of %d and %d is: %d\n", num1, num2, mul);
  }
}

Output:

Enter first number: 4
Enter second number: 5
Multiplication of 4 and 5 is: 20

Explanation:

In the above program, we imported the "java.util.Scanner" package to read input from the user. And, we created a public class Main. It contains a static method main().

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to perform subtraction without using ... >>
<< Java program to calculate HCF of two numbers...