I have been trying to figure out this problem, any help would be appreciated. I am supposed to create a header of asterisks which is supposed to be a method like this:
I am completely stumped, I am able to create the two long lines of 60 asteriks and the left most 3 asteriks but can't get the last 3 or have any clue how to get the message to print.
this is what I have to print just the basic lines:
for (int x = 0; x <= 60; x++){
System.out.print("*");
}
System.out.println("\n***");
for (int x = 0; x <= 60; x++){
System.out.print("*");
}
System.out.println("");
which prints out:
Any help would be great.
Edited code:
public static void main(String[] args)
{
String msg = "";
Scanner in = new Scanner(System.in);
int whiteSpace;
System.out.println("Enter your message: ");
msg = in.nextLine();
if(msg.length() < 54)
{
for (int x = 0; x <= 60; x++)
{
System.out.print("*");
}
System.out.println("\n***");
whiteSpace = (54 - (msg.length())/2);
for (int x = 0; x<=whiteSpace; x++)
{
System.out.print(" ");
}
System.out.print(msg);
for (int x = 0; x<=whiteSpace; x++)
{
System.out.print(" ");
}
System.out.print("\n***");
for (int x = 0; x <= 60; x++)
{
System.out.print("*");
}
System.out.println("");
}
}
and I get this: