Alright, I'm doing the program that asks for the length and height of a box. That part I got. What I can't seem to get is the part where it asks for an input by the user of which character to use when creating the box. Here's the code. Please help.
EDIT: Cleaner code.
EDIT: Cleaner code.
Code:
import java.util.Scanner;
import java.lang.*;
/**
* Michael Cuiffi
* Period 8
* 2/1/07
**/
public class DrawBox {
public static void drawBox(int length, int height, String mark) {
for (int i = 1; i <= height; i++){
drawBar(length, mark);
}
System.out.println();
}
public static void drawBar(int length, String mark) {
for (int i = 1; i <= length; i++) {
System.out.print(mark);
}
System.out.println();
}
public static void main(String[] args) {
int length, height;
String mark;
String choice;
Scanner s = new Scanner(System.in);
System.out.print("Please enter the box's length: ");
length = s.nextInt();
System.out.print("Please enter the box's height: ");
height = s.nextInt();
System.out.print("Do you want to enter a character to use to display the box?\n(enter y for yes): ");
choice = s.nextLine();
System.out.println();
if (choice != "Y") {
drawBox(length, height, "*");
} else if (choice == "Y") {
System.out.print("Please enter the character: ");
mark = s.nextLine();
drawBox(length, height, mark);
}
}
}
CSLib UGH!
Comment