ICSE Class 9 Computer Applications Question 2 of 17

Nested for loops — Question 2

Back to all questions
2
Question

Question 2

Write a program to print the series given below.

5 55 555 5555 55555 555555

Answer
public class Kboat5Series
{
    public static void main(String args[]) {
        
        for (int i = 1; i <= 6; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print('5');
            }
            System.out.print(' ');
        }
    }
}
Output
BlueJ output of Kboat5Series.java