Are You Feeling any difficulity while writing Core-Java Programs. Send those to me Here.

Number Series-2

Program: 6
public class HelloWorld{
     public static void main(String []args){
        for(int i=1;i<=5;i++){
            for(int j=i;j<=5;j++){
                System.out.print(j);
            }
            System.out.println("");
        }
     }
}
Output:
1  2  3  4  5
2  3  4  5
3  4  5
4  5
5
Program: 7
public class HelloWorld{
     public static void main(String []args){
        for(int i=1;i<=5;i++){
            for(int j=5;j>=i;j--){
                System.out.print(j);
            }
            System.out.println("");
        }
     }
}
Output:
5  4  3  2  1
5  4  3  2
5  4  3
5  4
5
Program: 8
public class HelloWorld{
     public static void main(String []args){
        for(int i=5;i>=1;i--){
            for(int j=5;j>=i;j--){
                System.out.print(j);
            }
            System.out.println("");
        }
     }
}
Output:
5
5  4
5  4  3
5  4  3  2
5  4  3  2  1
Program: 9
public class HelloWorld{
     public static void main(String []args){
        for(int i=5;i>=1;i--){
            for(int j=5;j>=i;j--){
                System.out.print(i);
            }
            System.out.println("");
        }
     }
}
Output:
5
4  4
3  3  3
2  2  2  2
1  1  1  1  1
Program: 10
public class HelloWorld{
     public static void main(String []args){
        for(int i=1;i<=5;i++){
            for(int k=1;k<i;k++)
            System.out.print(" ");
            for(int j=5;j>=i;j--){
                System.out.print(i);
            }
            System.out.println("");
        }
     }
}
Output:
1  1  1  1  1
   2  2  2  2
      3  3  3
         4  4
            5





No comments:

Post a Comment