Simple But Interesting Pattern
Logic used by programmer is much more important than syntax of any programming language.
If you really want to build upon your logic for programming - then try to create simple pattern like A, B, other number patterns etc. which really help in developing conditional handling of scenarios.
When I first started programming almost 6 years back, I used to take up different challenging programs to code by myself. So I did code all A to Z patterns, many other number patterns, etc.
Here are code snippets of few patterns -
1) Pattern of Uppercase Alphabet "A" -
** Here, User will input Height (and/or width of this pattern)
* * And program will output, output as shown...
*****
* *
Code - (its in Java, but can be easily converted for any other programming language)
2) Pattern of Uppercase Alphabet "B" -
3) Pattern of Uppercase Alphabet "C" -
The same way patterns-programs can be written for lower case letters or symbols or any other shapes, and when its really a fun and a challenge before we complete it.
So go and try out your brain in your free time this way.
If you really want to build upon your logic for programming - then try to create simple pattern like A, B, other number patterns etc. which really help in developing conditional handling of scenarios.
When I first started programming almost 6 years back, I used to take up different challenging programs to code by myself. So I did code all A to Z patterns, many other number patterns, etc.
Here are code snippets of few patterns -
1) Pattern of Uppercase Alphabet "A" -
** Here, User will input Height (and/or width of this pattern)
* * And program will output, output as shown...
*****
* *
Code - (its in Java, but can be easily converted for any other programming language)
/**
* By - Pramod khare
* **
* *
* *
********
* *
* *
* *
For User input - 7
* @param size
*/
public static void getPatternA(int size){
for(int i=1;i<=size;i++){
for(int j=0;j<=(2*size);j++){
if((j==(i+size)) || (j == (size-(i-1)))){
System.out.print("*");
}else if(i==((size/2)+1)){
if((j>= i) && (j<=(i+size-1))){
System.out.print("*");
}else{
System.out.print(" ");
}
}else{
System.out.print(" ");
}
}
System.out.print("\n");
}
}
2) Pattern of Uppercase Alphabet "B" -
/** * By - Pramod khare * **** * * * * * * **** * * * * * * **** For User input - 9 * @param size - height of pattern */ public static void getPatternB(int size){ for(int i=1;i<=size;i++){ for(int j=1;j<=((size/2)+1);j++){ if((i==1) && (j == ((size/2)+1))){ System.out.print(" "); }else if((i==((size/2)+1)) && (j == ((size/2)+1))){ System.out.print(" "); }else if((i == size) && (j ==((size/2)+1))){ System.out.print(" "); }else{ if(i == 1 || j ==1 || i == ((size/2)+1) || j == ((size/2)+1) || i == size){ System.out.print("*"); }else{ System.out.print(" "); } } } System.out.print("\n"); } }
3) Pattern of Uppercase Alphabet "C" -
/**
* By - Pramod khare
* ***
*
*
*
*
***
For User input - 6
* @param size - height of pattern
*/
public static void getPatternC(int size){
for(int i=1;i<=size;i++){
for(int j=1;j<=((size/2)+1);j++){
if((i==1 && j ==1) || (i==size && j==1)){
System.out.print(" ");
}else if((i == size) || (j == 1) || (i == 1)){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.print("\n");
}
}
The same way patterns-programs can be written for lower case letters or symbols or any other shapes, and when its really a fun and a challenge before we complete it.
So go and try out your brain in your free time this way.
Comments
Post a Comment