Originally I had the program all in main but I wanted to separate this by having the comparison method (diamond of asterisks) in its own method. For some odd reason I'm getting weird errors that won't allow the program to run.

Errors below:
1) Systan error on token "," delete this token
2) Sytax error on token "}" delete this token
3) Syntax error on token "k," variable declared...
4) Syntax error again!


Any help would be appreciated...

import javax.swing.JOptionPane;
public class Diamond 
{

	public static void main(String[] args)
	{
		
		String rowNum;
		int row; //# of rows "odd"
		int n, i, j,k;
		
		//display message
		rowNum = JOptionPane.showInputDialog("Enter a ODD number");
		row = Integer.parseInt(rowNum);
		// assign input number to n
		n = row;
		
		//display value entered
		System.out.println("The number entered was " + n + " below you will find your diamond.");
		diamondOFAsterisks();
	}
}

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

Well, I rearranged some things and counted parentheses and moved the function back inside of the class:

I also commented out the last line because the values are not yet set.
You should be able to fix it from here.

import javax.swing.JOptionPane;
public class Diamond
{
	private static void diamondOFAsterisks(int n, int i, int j, int k)
	{
		for(i = 1; i < n/2; i++)
		{
			for (k = n; k > i; k--)
				System.out.print(" ");
			for (j = 1; j <= i; j++)
				System.out.print("" + " ");
			System.out.println();

		}

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

	public static void main(String[] args)
	{

		String rowNum;
		int row; //# of rows "odd"
		int n, i, j,k;

		//display message
		rowNum = JOptionPane.showInputDialog("Enter a ODD number");
		row = Integer.parseInt(rowNum);
		// assign input number to n
		n = row;

		//display value entered
		System.out.println("The number entered was " + n + " below you will find your diamond.");
		//diamondOFAsterisks(n,i,j,k);
	}
}

Fixed the problem, thanks sir.

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.