ADVERTISEMENT
ADVERTISEMENT

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

Given two numbers, write a Java program to multiply two numbers using plus "+" operator.
Submitted by Nidhi, on February 23, 2022

Problem Solution:

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().

The main() method is an entry point for the program. And, we read two integer numbers from the user using the nextInt() method and calculated the multiplication of input numbers using the "+" operator with "for" loop and printed the result.

Java Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.