Java Tutorial
🔍
What is OOP?Classes & ObjectsConstructorsAccess Modifiersthis Keywordstatic KeywordEncapsulationInheritancesuper KeywordMethod OverridingOverloading vs OverridingPolymorphismUpcasting & Downcastinginstanceof OperatorAbstractionAbstract ClassesInterfacesMarker InterfacesAbstract Class vs InterfaceObject ClasstoString() Methodequals() & hashCode()
Collections OverviewCollections HierarchyIterable InterfaceCollection InterfaceMap Interfaceequals() and hashCode()IteratorListIteratorFail-fast vs Fail-safe IteratorConcurrentModificationExceptionArrayListLinkedListHashSetLinkedHashSetTreeSetQueuePriorityQueueDequeArrayDequeHashMapLinkedHashMapTreeMapConcurrentHashMapCopyOnWriteArrayListList vs Set vs MapChoosing the Right CollectionComparableComparatorComparable vs ComparatorCollections Utility ClassArrays Utility ClassImmutable CollectionsCollection vs CollectionsVectorHashtableStackArrayList Internal WorkingLinkedList Internal WorkingHashMap Internal WorkingTreeMap Internal Working
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
aholds6andbholds7. - 2
a * bevaluates to42, the product of the two values. - 3The result is stored in
productand 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