Monday, 5 January 2015

Java Code for Number Pattern ( Pattern of 1,2,3,...9)

Java Code for Number Pattern ( Pattern of 1,2,3,...9)


/*

   PATTERN

      1
     212
    32123
   4321234
  543212345
 -----------
-------------

*/


/********************* CODE *********************/

import java.util.*;
class pattern10
{
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);

System.out.println("Enter the number of rows ");
int n=scr.nextInt();

for(int i=1;i<=n;++i)
{
for(int j=1;j<=n-i;++j)
{
System.out.print(" ");
}

for(int k=i;k>=1;--k)
{
System.out.print(k);
}
for(int l=2;l<=i;++l)
{
System.out.print(l);
}

System.out.println();
}

}// end of main method
}// end of main class



/*
OUTPUT

C:\Users\Aditya\Desktop\aditya>javac pattern10.java
C:\Users\Aditya\Desktop\aditya>java pattern10

Enter the number of rows
6

     1
    212
   32123
  4321234
 543212345
65432123456


*/

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More