Advertisement
ThanosIsCool

4.11.1: Program: Drawing a half arrow (Java)

Jul 22nd, 2019
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  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.         // int i = 0;
  10.  
  11.         System.out.println("Enter arrow base height: ");
  12.         arrowBaseHeight = scnr.nextInt();
  13.  
  14.         System.out.println("Enter arrow base width: ");
  15.         arrowBaseWidth = scnr.nextInt();
  16.  
  17.         System.out.println("Enter arrow head width: ");
  18.         arrowHeadWidth = scnr.nextInt();
  19.        
  20.         while (arrowHeadWidth <= arrowBaseWidth) {
  21.       System.out.println("Enter arrow head width: ");
  22.       arrowHeadWidth = scnr.nextInt();
  23.       }
  24.  
  25.         // printing arrow base
  26.         for (int h = 0; h < arrowBaseHeight; ++h) {
  27.             // printing single line - every line is the same
  28.             for (int w = 0; w < arrowBaseWidth; w++)
  29.                 System.out.print("*");
  30.             // finishing line
  31.             System.out.println();
  32.         }
  33.  
  34.         // printing arrow head
  35.         // starting with provided width and decreasing it with every iteration
  36.         for (int a = arrowHeadWidth; a > 0; a--) {
  37.             // printing single line - now every line is different
  38.             // you have to count how many asterisks you are printing
  39.             for (int i = 0; i < a; i++)
  40.                 System.out.print("*");
  41.             // finishing line
  42.             System.out.println();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement