IT Developer

Nested for Loops in Java

Chapter 10

Nested for Loops in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Series Printing - Repeated Digit 8


4. Write a program to print the series given below.

8 88 888 8888 88888 888888

Program Title: Series Printing - Repeated Digit 8

public class SeriesEight {

    public static void main(String[] args) {

 

        int num = 0;

 

        for (int i = 1; i <= 6; i++) {

            num = num * 10 + 8;

            System.out.print(num + " ");

        }

    }

}

Output

Sample Output 
8 88 888 8888 88888 888888

📝 Explanation

  • Start with num = 0
  • Each time:

                  num = num * 10 + 8

  • This keeps adding one more 8 to the number.

Example:

  • 0 × 10 + 8 = 8
  • 8 × 10 + 8 = 88
  • 88 × 10 + 8 = 888
  • and so on...