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

zarina's blog

zarina's picture

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

5
Your rating: None Average: 5 (2 votes)
  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.        
zarina's picture

Java Number Diagonal using For Loop

3
Your rating: None Average: 3 (2 votes)
  1. /*
  2.     Write a program to output the following pattern using for loop.
  3.   1
  4.     2
  5.      3
  6.        4
  7.          5
  8. */
  9.  
  10. public class Diagonal {
  11.  
  12.     public static void main (String[]args) {
  13.  
  14.           for (int x=1; x<=5; x++){
  15.                for (int y=1; y<=x; y++){
  16.                  System.out.print("");
  17.                }
  18.                System.out.println(x);
  19.      
Syndicate content