Friday, 22 July 2011

Program for the below pattern without using 'for' loop

0
10
010
1010
01010

public class Design1 {

    private static int printNumber(int data) {
        System.out.print(data % 2);
        return data > 0 ? printNumber(data - 1) : 0;
    }
    private static int iterate(int noOfRows) {
        int currentnoOfRows = noOfRows > 0 ? iterate(noOfRows - 1) : 0;
        System.out.println();
        return printNumber(noOfRows);
    }
    public static void main(String[] args) {
        iterate(10);
        System.out.println();
    }
}

No comments:

Post a Comment