fork download
  1. import java.util.Scanner;
  2.  
  3. public class DrawHalfArrow {
  4. public static void main(String[] args) {
  5. Scanner scnr = new Scanner(System.in);
  6. int arrowBaseHeight = 0;
  7. int arrowBaseWidth = 0;
  8. int arrowHeadWidth = 0;
  9.  
  10.  
  11.  
  12. System.out.print("Enter arrow base height: ");
  13. arrowBaseHeight = scnr.nextInt();
  14.  
  15. System.out.print("Enter arrow base width: ");
  16. arrowBaseWidth = scnr.nextInt();
  17.  
  18. System.out.print("Enter arrow head width: ");
  19. arrowHeadWidth = scnr.nextInt();
  20.  
  21. //make sure arrow head width is larger than base width
  22.  
  23. while (arrowHeadWidth <= arrowBaseWidth) {
  24. System.out.println("Enter arrow head width: ");
  25. arrowHeadWidth = scnr.nextInt();
  26. }
  27.  
  28.  
  29. //draw arrow base
  30.  
  31. System.out.println();
  32.  
  33. for (int i = 1; i <= arrowBaseHeight; i++) {
  34. for (int j = 1; j <= arrowBaseWidth; j++) {
  35. System.out.print("*");
  36. }
  37. System.out.println();
  38. }
  39.  
  40.  
  41. //draw arrow head
  42.  
  43. for (;arrowHeadWidth > 0; arrowHeadWidth--) {
  44. for (int j = 1; j <= arrowHeadWidth; j++) {
  45. System.out.print("*");
  46. }
  47. System.out.println();
  48. }
  49.  
  50.  
  51.  
  52. return;
  53. }
  54. }
  55.  
  56. //Base Loop
  57. while (arrowBaseHeight > 0){
  58. while (arrowBaseWidth > 0){
  59. // Draw arrow base (height = 3, width = 2)
  60. System.out.println("*");
  61. System.out.print("*");
  62. arrowBaseWidth = arrowBaseWidth - 1;
  63. arrowBaseHeight = arrowBaseHeight - 1;
  64. }
  65. }
  66. // Draw arrow head (width = 4)
  67. // System.out.println("****");
  68. //System.out.println("***");
  69. //System.out.println("**");
  70. //System.out.println("*");
  71.  
  72. return;
  73. }
  74. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5 4 3
compilation info
Main.java:57: error: class, interface, or enum expected
      while (arrowBaseHeight > 0){
      ^
Main.java:61: error: class, interface, or enum expected
      System.out.print("*");
      ^
Main.java:62: error: class, interface, or enum expected
      arrowBaseWidth = arrowBaseWidth - 1;
      ^
Main.java:63: error: class, interface, or enum expected
      arrowBaseHeight = arrowBaseHeight - 1;
      ^
Main.java:64: error: class, interface, or enum expected
      }
      ^
Main.java:73: error: class, interface, or enum expected
   }
   ^
6 errors
stdout
Standard output is empty