Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Write a program to generate following pattern using for loop and if statement

  1. /*
  2.     Write a program to generate following pattern using for loop and
  3.     if statement.
  4.    
  5.     1
  6.     22
  7.     333
  8.     4444
  9.     55555
  10.     6666
  11.     777
  12.     88
  13.     9
  14. */
  15. public class iffor{
  16.    
  17.     public static void main(String args[]){
  18.    
  19.         for (int x=1; x<=9; x++){
  20.    
  21.           if(x<=5){
  22.              
  23.               for(int y=1; y<=x; y++){
  24.                   System.out.print(x);
  25.               }
  26.               System.out.println("");
  27.             }
  28.             else{
  29.                 for(int z=9; z>=x; z--){
  30.                     System.out.print(x);
  31.                 }
  32.                 System.out.println("");
  33.             }
  34.         }
  35.     }
  36. }
Your rating: None Average: 5 (2 votes)
Share this
Anonymous's picture

It really helped, thanks

It really helped, thanks
Anonymous's picture

1 *2

1 *2 **36 ***479 ****581011 print this
Anonymous's picture

if got solution please send

if got solution please send it to jagd813@gmail.com
Anonymous's picture

Thanks for the code. It is

Thanks for the code. It is very useful. can you make the flag of usa or philippines, germany or other country's flag using the loop? like this * * * * * * ================== * * * * * * *----------------------------------- * * * * * * ================== * * * * * * *----------------------------------- ========================= -------------------------------------------------- =========================
Anonymous's picture

plz send

plz send this C CO COM COMP COMPU COMPUT COMPUTE COMPUTER
Anonymous's picture

how do you

how do you print 1AAAA 22BBB 333CC 4444D 55555
Anonymous's picture

how do you

how do you print 1AAAA 22BBB 333CC 4444D 55555
Anonymous's picture

Many automotive repairs or

Many automotive repairs or diagnostic tools require the use of ADS-1 Scanner, it will last a long time and are the most common tools used to loosen bolts and nuts.
Anonymous's picture

how to create this

how to create this pattern??/ 1 212 32123 4321234 543212345 4321234 32123 212 1
Anonymous's picture

how to create this pattern??

how to create this pattern?? 1 212 32123 4321234 543212345 4321234 32123 212 1

Post new comment

1 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.