fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String pattern;
  13. int noOfTimes;
  14.  
  15. Scanner scanner = new Scanner(System.in);
  16.  
  17. System.out.print("Enter the pattern to print : ");
  18. pattern = scanner.nextLine();
  19.  
  20. System.out.print("Enter number of times it should get printed : ");
  21. noOfTimes = scanner.nextInt();
  22.  
  23. for(int i=1; i<=noOfTimes; i++) {
  24.  
  25. System.out.println();
  26.  
  27. if(i==1 || i==noOfTimes) {
  28.  
  29. for(int j=1; j<=noOfTimes; j++){
  30.  
  31. System.out.print(pattern+" ");
  32.  
  33. }
  34. }
  35. else {
  36.  
  37. for(int k=1; k<=noOfTimes;k++) {
  38.  
  39. if(k==1 || k == noOfTimes) {
  40.  
  41. System.out.print(pattern + " ");
  42.  
  43. }
  44. else {
  45.  
  46. System.out.print(" ");
  47.  
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
Success #stdin #stdout 0.1s 380736KB
stdin
*
7
stdout
Enter the pattern to print : Enter number of times it should get printed : 
* * * * * * * 
*           * 
*           * 
*           * 
*           * 
*           * 
* * * * * * *