Hi the project i have is
Write a program that displays diamonds as text using a character provided by the user. For example,
a diamond of height 6 constructed from asterisks will display as follows:
__*
_***
*****
*****
_***
__*
(I cant make it line up perfectly... )
after finishing making the project and turn in the code to the server for the robot to check the mistakes i ended up failing many tests.
one of those tests were the NoCharacter test which tests whether no character was entered at the appropriate prompt. If no character was entered, it will prompt again.

The test Lower tests lower case. Additionally, the character it chooses to use is a space. Therefore, the output is a diamond of spaces.
i tried doing this by myself for a whole week and i came here to find some help since the due day has already passed

how do you make it prompt again after certain amount time and make spaces with diamond??

import java.util.Scanner;

public class Pattern 
{
    public static void main(String[] args) 
    {

        Scanner kb = new Scanner(System.in);
        String input;
        String character;
      
        do 
        {
            System.out.print("Enter diamond size (\"short\", \"average\", or \"tall\"): ");
            input = kb.next().toLowerCase();
        }
        while (checkSize(input) == -1);
        do 
        {
            System.out.print("Enter pattern character: ");
            character = kb.next();
        } 
        while (character.length() > 1);
      
          char ch = character.charAt(0);
      
          displayPattern(checkSize(input), ch);
    }
    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;
        }
        return -1;
    }

    public static void displayPattern (int size, char ch)
    {
        int i,j,k;
        for(i = size / 2; i > 0; i--)
        {
            for(j = 1; j < i; j++)
            {
                System.out.print(" ");
            }
	    for(k = size; k >= j * 2; k--)
            {
                System.out.print(ch);
            }
            System.out.println();
        }  

        for (i = 1; i <= size / 2; i++)
        {

            for(j = 1; j < i; j++)
            {
                System.out.print(" ");
            }
	    for(k = size; k >= j * 2; k--)
            {
                System.out.print(ch);
            }
            System.out.println();
      }
   }
}

I don't understand your question. can you explain a bit more what you're trying to do?
are you trying to get your code to ask you again for input after your diamond has been printed?

I don't understand your question. can you explain a bit more what you're trying to do?
are you trying to get your code to ask you again for input after your diamond has been printed?

The test NoCharacter tests whether no character was entered at the appropriate prompt. If no character was entered, it will prompt again.
i think it is suppose to promt again if dont put any character for some time i think.. not too sure myself so i keep failing
and other one is making diamond with just spaces

well ... if no character is entered, you're program is still waiting for the input. it won't go further untill you've actually provided one.

d

and how did you solve it? it might help the next person looking for a sollution to this problem solve his faster if you posted your sollution here.

input = kb.nextLine().toLowerCase();
while ((checkSize(input) == -1) || (input.length() == 0));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.