🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Java Notes
Topic #50

Real-Life Examples


Real-Life Examples

To demonstrate a practical example of the for loop, let's create a program that counts to 100 by tens:

Example

for (int i = 0; i <= 100; i += 10) {
  System.out.println(i);
}

In this example, we create a program that only print even values between 0 and 10:

Example

for (int i = 0; i <= 10; i = i + 2) {
  System.out.println(i);
}

And in this example, we create a program that prints the multiplication table for a specified number:

Example

int number = 2;

// Print the multiplication table for the number 2
for (int i = 1; i <= 10; i++) {
  System.out.println(number + " x " + i + " = " + (number * i));
}

Here is a simple program that prints the seat numbers in a theater row:

Example

for (int seat = 1; seat <= 5; seat++) {
  System.out.println("Seat number: " + seat);
}

Use a loop to calculate the factorial of a given number:

Example

int n = 5;
int fact = 1;

for (int i = 1; i <= n; i++) {
  fact *= i;
}

System.out.println("Factorial of " + n + " is " + fact);
// Output: Factorial of 5 is 120

Note: Factorial means multiplying a number by every number below it, down to 1. For example, the factorial of 5 is: 5 * 4 * 3 * 2 * 1 = 120

Want to go beyond the notes?

Join CodingNow 2.0's Java course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Real-Life Examples – FAQs

Quick answers about learning Real-Life Examples in Java.

This free note from CodingNow 2.0 explains Real-Life Examples in Java — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Java topic on CodingNow 2.0, including Real-Life Examples, is 100% free with no signup required.
With focused practice, most students grasp Real-Life Examples in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now