Advertisement
Guest User

MMasignment

a guest
Feb 25th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5.  
  6. Scanner sc = new Scanner(System.in);
  7.  
  8. int n = Integer.parseInt(sc.nextLine());
  9.  
  10. if( n%2 == 1 && n>2 && n<=10000){
  11.  
  12. for(int i = 0; i < (n + 1)/2;i++){
  13.  
  14. System.out.print(printChar('-',n-i));
  15. System.out.print(printChar('*',n+2*i));
  16. System.out.print(printChar('-',n-2*i));
  17. System.out.print(printChar('*',n+2*i));
  18. System.out.print(printChar('-',2*(n-i)));
  19. System.out.print(printChar('*',n+2*i));
  20. System.out.print(printChar('-',n-2*i));
  21. System.out.print(printChar('*',n+2*i));
  22. System.out.print(printChar('-',n-i));
  23. System.out.println();
  24.  
  25. }
  26.  
  27. for(int j = 0;j < (n - 1)/2;j++){
  28.  
  29. System.out.print(printChar('-',(n-1)/2-j));
  30. System.out.print(printChar('*',n));
  31. System.out.print(printChar('-',1+2*j));
  32. System.out.print(printChar('*',2*n-1-2*j));
  33. System.out.print(printChar('-',1+2*j));
  34. System.out.print(printChar('*',n));
  35. System.out.print(printChar('-',n-1-2*j));
  36. System.out.print(printChar('*',n));
  37. System.out.print(printChar('-',1+2*j));
  38. System.out.print(printChar('*',2*n-1-2*j));
  39. System.out.print(printChar('-',1+2*j));
  40. System.out.print(printChar('*',n));
  41. System.out.print(printChar('-',(n-1)/2-j));
  42. System.out.println();
  43.  
  44. }
  45.  
  46. System.out.print(printChar('*',n));
  47. System.out.print(printChar('-',n));
  48. System.out.print(printChar('*',n));
  49. System.out.print(printChar('-',n));
  50. System.out.print(printChar('*',n*2));
  51. System.out.print(printChar('-',n));
  52. System.out.print(printChar('*',n));
  53. System.out.print(printChar('-',n));
  54. System.out.print(printChar('*',n));
  55.  
  56. }
  57.  
  58. }
  59.  
  60. public static String printChar(String char, int count) {
  61.  
  62. String output = "";
  63.  
  64. for(int i=0; i<count; i++) {
  65.  
  66. output = output + char;
  67. }
  68. return output;
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement