After getting help and configuring my diamond program, I still am having trouble
ID: 3621952 • Letter: A
Question
After getting help and configuring my diamond program, I still am having trouble getting the do while loop to end after entering the correct input. If anybody can help me resolve this issue, I would greatly appreciate it!
Here is my program:
// This program displays diamonds as text using a character provided by the user
import java.util.Scanner;
public class Pattern
{
public static void main(String [] args)
{
Scanner kb = new Scanner(System.in);
String input;
int size;
char character;
do
{
System.out.print("Enter a diamond size ("short", "average","tall"): ");
input = kb.nextLine().toLowerCase();
//function call to get size
size = checkSize(input);
System.out.print("Enter pattern character: ");
input=kb.nextLine();
character=input.charAt(0);
//function call to display pattern
displayPattern(size,character);
}while((input!="short")&&(input!="average")&&(input!="tall"));;
}
public static int checkSize(String size)
{
if(size.equals("short"))
return 6;
else if(size.equals("average"))
return 12;
else if(size.equals("tall"))
return 22;
else
return -1;
}
public static void displayPattern(int size, char ch)
{
for(int i = size; i >= 1; i-- )
{
int j;
for( j = 1; j < i; j++ )
{
System.out.print(" ");
}
for(int k=size; k >= j*2; k-- )
{
System.out.print(ch);
}
System.out.println();
}
for(int i = 2; i <= size; i++ )
{
System.out.print(" ");
int j;
for( j = 2; j < i; j++ )
{
System.out.print(" ");
}
for( int k = size; k >= j * 2; k-- )
{
System.out.print(ch);
}
System.out.println();
}
}
}
Here is the output:
java Pattern
Enter a diamond size ("short", "average","tall"): short
Enter pattern character: m
m
mmm
mmmmm
mmm
m
Enter a diamond size ("short", "average","tall"):