Friday 25 July 2014

Examples of loop with output in java code

class Loops
{
                public static void main(String args[])
                {
                                int i;
                                for(i=0; i<10; i += 2)
                                System.out.print(" " + i);
                                System.out.println();

                                for(i=100; i>=0; i -= 7)
                                System.out.print(" " + i);
                                System.out.println();

                                for(i=1; i<=10; i += 1)
                                System.out.print("*" + ++i);
                                System.out.println();

                                for(i=2; i<100; i *= 2)
                                System.out.print(" " + i);
                }
}
Output:
0 2 4 6 8
100 93 86 79 72 65 58 51 44 37 30 23 16 9 2
*2*4*6*8*10

2 4 8 16 32 64

No comments:

Post a Comment