Saturday, 14 June 2014

java program to print a given pattern of " * " and " _ " as below .......

to print following pattern...
* * * * * *
* * * *_ _
* *_ _ _ _
_ _ _ _ _ _      

here is the code ..

       
import java.io.*;
class asteriskprint {
 public static void main(String args[]) {
  for (int i = 0; i < 4; i++) {
   for (int k = 0; k < 6 - 2 * i; k++) {
    System.out.print("*");
   }
   for (int h = 0; h < 2 * i; h++)
    System.out.print("_");
   System.out.println("\n");
  }
 }
}

       
 

No comments:

Post a Comment