Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package displaybox2;
- import java.util.Scanner;
- /**
- *
- * @author Monty
- */
- public class DisplayBox2 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String ans, cha, height, width;
- System.out.print("Enter height: ");
- height = input.nextLine();
- System.out.print("\nEnter width: ");
- width = input.nextLine();
- System.out.print("\nWould you like to use a special character? (y/n): ");
- ans = input.nextLine();
- if (ans.equalsIgnoreCase("y")) {
- System.out.print("\nEnter character: ");
- cha = input.nextLine();
- drawbox(height, width, cha);
- } else {
- drawbox(height, width);
- }
- }
- public static void drawbar(String height, String width) {
- int w = Integer.parseInt(width);
- for (int i = 0; i < w; i++) {
- System.out.print("#");
- }
- System.out.print("\n");
- }
- public static void drawbox(String height, String width) {
- int h = Integer.parseInt(height);
- for (int i = 0; i < h; i++) {
- drawbar(height, width);
- }
- }
- public static void drawbar(String height, String width, String cha) {
- int w = Integer.parseInt(width);
- for (int i = 0; i < w; i++) {
- System.out.print(cha);
- }
- System.out.print("\n");
- }
- public static void drawbox(String height, String width, String cha) {
- int h = Integer.parseInt(height);
- for (int i = 0; i < h; i++) {
- drawbar(height, width, cha);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment