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
Divide Two Numbers in Java
beginner· Basics & I/O · Arithmetic
Problem
Dividing two int values in Java performs integer division, discarding any remainder.
Given two integers, divide the first by the second and print the result.
Input
20, 4
Output
Quotient: 5
Java Program
Java
public class DivideTwoNumbers {
public static void main(String[] args) {
int a = 20;
int b = 4;
int quotient = a / b; // integer division — no fractional part
System.out.println("Quotient: " + quotient);
}
}Output
Quotient: 5
Core Logic
The / operator between two int values performs integer division, keeping only the whole-number part of the result.
How It Works
- 1
aholds20andbholds4. - 2
a / bevaluates to5, since 20 divides evenly by 4. - 3The result is stored in
quotientand printed with a label.
With
a = 20 and b = 4, a / b evaluates to 5, so the program prints "Quotient: 5".💡
Key Point: int division truncates any remainder — 7 / 2 gives 3, not 3.5. Use double values (or a cast) when a fractional result is needed.
Key Concepts
/ operatorinteger divisionint