Monty374

Box2

Oct 18th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package displaybox2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. *
  7. * @author Monty
  8. */
  9. public class DisplayBox2 {
  10.  
  11. /**
  12. * @param args the command line arguments
  13. */
  14. public static void main(String[] args) {
  15. Scanner input = new Scanner(System.in);
  16. String ans, cha, height, width;
  17.  
  18. System.out.print("Enter height: ");
  19. height = input.nextLine();
  20.  
  21. System.out.print("\nEnter width: ");
  22. width = input.nextLine();
  23.  
  24. System.out.print("\nWould you like to use a special character? (y/n): ");
  25. ans = input.nextLine();
  26.  
  27. if (ans.equalsIgnoreCase("y")) {
  28. System.out.print("\nEnter character: ");
  29. cha = input.nextLine();
  30. drawbox(height, width, cha);
  31.  
  32. } else {
  33. drawbox(height, width);
  34. }
  35.  
  36. }
  37.  
  38. public static void drawbar(String height, String width) {
  39. int w = Integer.parseInt(width);
  40. for (int i = 0; i < w; i++) {
  41. System.out.print("#");
  42. }
  43. System.out.print("\n");
  44. }
  45.  
  46. public static void drawbox(String height, String width) {
  47. int h = Integer.parseInt(height);
  48. for (int i = 0; i < h; i++) {
  49. drawbar(height, width);
  50. }
  51. }
  52.  
  53. public static void drawbar(String height, String width, String cha) {
  54. int w = Integer.parseInt(width);
  55. for (int i = 0; i < w; i++) {
  56. System.out.print(cha);
  57. }
  58. System.out.print("\n");
  59. }
  60.  
  61. public static void drawbox(String height, String width, String cha) {
  62. int h = Integer.parseInt(height);
  63. for (int i = 0; i < h; i++) {
  64. drawbar(height, width, cha);
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment