public static void main(String[] args) {
String r;
int w;
int h;
char c;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the text: ");
r=sc.nextLine();
System.out.println("Enter the character : ");
c = sc.next().charAt(0);
System.out.println("Enter your width: ");
w=sc.nextInt();
System.out.println("Enter your height: ");
h=sc.nextInt();
System.out.println();
textbox(c,r,w,h);
}
public static void textbox (char c, String r, int w, int h)
{
String middle = c + " " + r + " " + c;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (i == 0 || i == h-2) {
System.out.print(c);
} else if (j ==w-1) {
System.out.print(middle);
}
}
System.out.println();
}
}
}
I have to make the program use a method that accepts a string and prints the string centered horizontally on the screen surrounded by a box six characters longer than the message.
Limit the length of the string to ensure it will fit on the screen. It doesn't do what I want it to do, the rows don't match and it displays the word more than once(depending on the height).