I am trying to write a code that reads an integer and then diplays a diamond with the corresponding number of lines.

The program I have written displays a solid diamond, but I am only trying to display the outline. Here is my code:

import javax.swing.JOptionPane;


/**
 *Odd and even, if all input numbers are even 1 is displayed or if either number is odd 0 is displayed.
 * Cpsc118 Computer programming 1
 * INSTRUCTOR   John Roberts
 * ASSIGNMENT    Assignment #4, question #2
 * @author       ---------------------
 * @version      July 25 2010
 */

public class Diamond {
 
        public static void main(String args[]){
            int n,i,j,k;
     
     do { 
     
		n = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter number"));			
 
      }while(n % 2 == 0);
     
      System.out.println(n);
     
      System.out.println();   
     
     for (i = 1; i <= n; 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; i > 0; i--){
            
             for (k = n; k > i; k--)
               System.out.print(" ");
            
             for (j =1; j <= i; j++)
         System.out.print("*" + " ");
       
       System.out.println();
            
             }
}
}

To go from printing a solid diamond to only the outline, don't print the inside '*'s

You need to compute when you're on the inside and output spaces instead of *s
Perhaps you could use an if test.

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.