November 20th, 2012, 10:47 PM
Need help on my Homwork :( im totally new to this
i was asked to write a program that will display a diamond and a hollow diamond. It need to ask the user to input the size and character, which to form the diamond, and must use 3 methods.
• Public static int checkSize(String size) – This method will return 6 if size equals “short”, 12 if size equals “average”, 24 if size equals “tall”, or -1 otherwise. Be sure that the comparison is not case sensitive.
• Public static void displayDiamond (int size, char ch) – This method will display a diamond of height size constructed from pattern character ch.
• Public static void displayHollowDiamond (int size, char ch) – This method will display a hollow diamond of height size constructed from pattern character ch.
in main method i had to use a do-while loop also, until the user input "short","average","tall", for size of 6,12,24.
an output of "short" should look like ( "o"means space
And here is what i have so far (ive only completed the hollow diamond and no idea what to do for the other 2 methods.)
public class Diamonds
public static void main(String args)
Scanner kb = new Scanner(System.in);
System.out.print("enter diamond size (\"short\", \"average\", or \"tall\"): ");
input = kb.nextLine();
System.out.print("enter pattern character: ");
char character = kb.nextChar();
public static int checkSize(String size)
public static void displayDiamond(int size, char ch)
public static void displayHollowDiamond(int size, char ch)
int i, j, k, l;
for(i=1, i<=size; i++)
k = i<=size/2 ? 2*1-1 : 2*(size-i+1)-1;
j = (size-k)/2;
for(l=0; l<k; l++)
for(l=0; l<k; l++)
if(l==0 || l==k-1)
any hint and helps??
November 28th, 2012, 06:38 PM
I didn't get much of the project objectives but I think you can use this link: aisha91.hubpages.com/hub/Java-Source-Code-Recursive-Diamond-Shape-for-Asterisk
Comments on this post