Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default [SOLVED] Not having fun shape using loops!

    for this program i want to create a diamon shape by entering a odd number
    let say i entered 7
    ideal output is
    *
    ***
    *****
    *******
    *****
    ***
    *

    and my output is like a pyramid
    *
    ***
    *****
    *******
    *********
    ***********
    ************

    any suggestion of what i should do to fix it?
    Java Code:
    import java.util.Scanner;
    
      public class T6{
      	public static void main (String[]args){
    
      Scanner input = new Scanner(System.in);
    
      //enter a positive odd integer
      System.out.println("Enter a positive odd integer number: ");
    
      int numberOfLines = input.nextInt();
    
      //check number
    
      while ( numberOfLines <= 0 || numberOfLines%2 == 0){
      System.out.println("Enter a positive odd integer number again: ");
    
      numberOfLines = input.nextInt();
    }
    
    System.out.println("The input is: "+ numberOfLines);
    
    //shapes diamon
    
    for (int row = 1; row <= numberOfLines; row++){
    
    	for (int spac = 1; spac <= numberOfLines-row; spac++)
    		System.out.print(" ");
    
    	for (int num =  row; num >= 1; num--)
    		System.out.print("*");
    
    	for (int num = 2; num <= row; num++)
    		System.out.print("*");
    
    
    
    System.out.println();
    }
    
    
      	}
      }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    ok I got it!

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  5. #5
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Did you solve the problem?
    YUP~! Thankyou for your tip!=]

  6. #6
    chrisjake is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default

    Try to make it again without the use of scanner.... thank you..

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Help with Move Shape
    By romina in forum AWT / Swing
    Replies: 2
    Last Post: 12-09-2010, 03:25 AM
  2. Exponential Shape Program
    By checkmylongboarding in forum New To Java
    Replies: 3
    Last Post: 09-23-2008, 03:31 AM
  3. implementing shape
    By sidkdbl07 in forum Java 2D
    Replies: 1
    Last Post: 01-12-2008, 06:42 PM
  4. weird looking shape JButton is it possible?
    By unhurt in forum AWT / Swing
    Replies: 8
    Last Post: 11-03-2007, 09:10 AM
  5. How to change shape of JButton
    By FaRuK in forum AWT / Swing
    Replies: 1
    Last Post: 05-19-2007, 12:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •