Java Tutorial
🔍
Java ProgramsBasics & I/OMultiply Two Numbers

Multiply Two Numbers in Java

beginner·  Basics & I/O  ·  Arithmetic

Problem

Multiplying two numbers with the * operator scales one value by another.

Given two integers, multiply them and print the result.

Input
6, 7
Output
Product: 42

Java Program

Java
public class MultiplyTwoNumbers { public static void main(String[] args) { int a = 6; int b = 7; int product = a * b; System.out.println("Product: " + product); } }

Output

Product: 42

Core Logic

The * operator multiplies two int values directly, producing their product in a single expression.

How It Works
  1. 1a holds 6 and b holds 7.
  2. 2a * b evaluates to 42, the product of the two values.
  3. 3The result is stored in product and printed with a label.
With a = 6 and b = 7, a * b evaluates to 42, so the program prints "Product: 42".
💡

Key Point: Multiplying two large int values can overflow the 32-bit int range silently — use long when the product might exceed about 2.1 billion.

Key Concepts

* operatorintarithmetic

Related Programs