Go to Top

Wednesday, 3 August 2011

To print the given pattern

Question 31 : Write a program in Java to print the following pattern : 

1
11
121
1331
14641

Java Program : 

class pattern_19
{
 static void main()
 {
     int i,j;
     int s=1;
     System.out.println(s);
     for(i=1;i<=4;i++)
     {
         for(j=1;j<=i;j++)
         {
             s=s*11;
            }
            System.out.println(s);
            s=1;
        }
    }
}

2 comments:

  1. Nice................
    Basic C Program for Computer Programmer who want to learn. If you have simple wish you may visit. To get all update stay with us.
    Outline:
    • Language: C and Simscript.
    • if (Condition) statement and Nested if statement is used to determine the given number is positive, negative, even or odd. Another way we solve this program using if-else-if ladder.
    • When the given condition or expression is true the statement associated with it executed.
    To know details:

    http://www.secufoon.com/write-a-c-program-for-determining-a-number-is-positive-negative-even-or-odd/

    ReplyDelete
  2. how to write print pascals traingle in java
    1
    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1

    ReplyDelete

ShareThis