Guest User

Untitled

a guest
Apr 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public class aufgabe5 {
  2.  
  3. /**
  4. * @param args
  5. */
  6. public static void main(String[] args) throws Exception {
  7.  
  8. char mark = 'a';
  9. char zeichen = '+';
  10. int zeichenLaenge = 7 ;
  11. int i = zeichenLaenge;
  12. //int j = 1;
  13. int zaehler;
  14. int wert;
  15.  
  16.  
  17. switch (mark){
  18. case 'a' :
  19.  
  20.  
  21. if (zeichenLaenge%2 != 0){ // prüfen ob länge durch 2 teilbar (ohne rest)
  22.  
  23.  
  24.  
  25. for (int j = zeichenLaenge ; j >= 1; j -= 2){
  26. for (int c = 0; c <= (zeichenLaenge - j)/2 ; c++)
  27. System.out.print(" ");
  28. for (int c = 1; c <= j; c++)
  29. System.out.print(zeichen);
  30.  
  31. System.out.println();
  32. }
  33. for (int j = 1 ; j <= zeichenLaenge; j += 2){
  34. for (int c = 0; c <= (zeichenLaenge - j)/2; c++)
  35. System.out.print(" ");
  36. for (int c = 1; c <= j ; c++)
  37. System.out.print(zeichen);
  38. System.out.println();
  39. }
  40. }
  41.  
  42. else{
  43.  
  44. for (int j = zeichenLaenge ; j >= 2; j -= 2){
  45. for (int c = 0; c <= (zeichenLaenge - j)/2 ; c++)
  46. System.out.print(" ");
  47. for (int c = 1; c <= j; c++)
  48. System.out.print(zeichen);
  49. for (int c = 0; c <= (zeichenLaenge - j)/2 ; c++)
  50. System.out.print(" ");
  51. System.out.println();
  52. }
  53. for (int j = 2 ; j <= zeichenLaenge; j += 2){
  54. for (int c = 0; c <= (zeichenLaenge - j)/2; c++)
  55. System.out.print(" ");
  56. for (int c = 1; c <= j ; c++)
  57. System.out.print(zeichen);
  58. for (int c = 0; c <= (zeichenLaenge - j)/2; c++)
  59. System.out.print(" ");
  60. System.out.println();
  61. }
  62. }
Add Comment
Please, Sign In to add comment