Results 1 to 7 of 7
  1. #1
    Gaby26 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default Help please with the pyramid of letters!!!I need this project for tomorrow

    THIS CLASS PRINTS THE PYRAMID OF LETTER EACH TIME THE USER GIVES A CHARACTER.
    FOR EXAMPLE:THE USER GIVES THE CHARACTER d,SO IT WILL BE DISPLAYED :

    ___ a ___ where _ is a space
    __aba__
    _abcba_
    abcdcba
    Since my project will have a Graphical display,the user will give the character in a JTextField of course.

    Now my question is: Is it possible to make this class a method(no main method) also without using System.out.println,since I want to use it later as a private field variable,inside my controller class.


    Java Code:
    import java.util.*; // For using Scanner class for input
     public class Pyramid_of_letters {
    	public static void main(String[]args){
    	    	 Scanner key = new Scanner(System.in);
    	          char middle = 'a'; 
    	        char input = key.next().charAt(0);
    	        int spaces = input - (int) 'a';
    	        while( middle <= input) {
    	            // Print the left side spaces
    	            for( int i = 0; i < spaces; i++)
    	            	 System.out.println(" ");
    	            // Print the left side of the tree (including the middle)
    	            for( char y = 'a'; y <= middle; y++)
    	            	 System.out.println(y);
    	            // Print the right side of the tree
    	            for( char y = Character.toChars( middle - 1)[0]; y >= 'a'; y--)
    	            	 System.out.println(y);
    	            // Print the right side spaces
    	            for (int i = 0; i < spaces; i++)
    	            	 System.out.println(" ");
    	            // Print a new line
    	                spaces--;
    	            // Increment the middle character
    	            middle++;
    	        
    			}
    		
    			
    	}
    }
    Last edited by Gaby26; 01-23-2013 at 09:08 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: Help please with the pyramid of letters!!!I need this project for tomorrow

    When posting code, please use the code tags to preserve formatting.

    You haven't asked a question. You can't simply dump some code here and demand somebody do your homework for you by tomorrow and expect a meaningful response.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Gaby26 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default Re: Help please with the pyramid of letters!!!I need this project for tomorrow

    CAN you just help me???

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: Help please with the pyramid of letters!!!I need this project for tomorrow

    Please do not privately message users asking for help. That's what the forum is for, and you still haven't asked an actual question.

    I suggest you read the link in my signature on asking questions the smart way, then post an SSCCE along with a specific technical question, and we'll go from there.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Gaby26 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default Re: Help please with the pyramid of letters!!!I need this project for tomorrow

    Is it better now?

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: Help please with the pyramid of letters!!!I need this project for tomorrow

    Is it possible to make this class a method? Sure, assuming by "class" you mean the code inside the main method. Simply put that inside another method, then call it from main.

    Can you avoid using System.out.println()? Sure. You're already using variables. What have you tried?

    I will ask you again to stop privately messaging me asking me to check on this post. That doesn't encourage people to help you, and it makes you seem impatient. There are dozens or hundreds of users here all with urgent questions, and we answer them when we can, for free, in our spare time. Keep that in mind, and perhaps next time you won't wait until the last minute to do your assignment.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,237
    Rep Power
    19

    Default Re: Help please with the pyramid of letters!!!I need this project for tomorrow

    Moved from AWT/Swing

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Convert English letters to Tamil letters
    By srinivasmallabathula in forum New To Java
    Replies: 1
    Last Post: 10-20-2012, 02:39 PM
  2. Draw a pyramid
    By MisterNikos in forum New To Java
    Replies: 23
    Last Post: 04-02-2012, 01:44 PM
  3. Need Help With Some Pyramid
    By lord raza in forum New To Java
    Replies: 1
    Last Post: 11-07-2011, 01:03 PM
  4. pyramid
    By Dashinator in forum New To Java
    Replies: 8
    Last Post: 11-15-2010, 09:10 PM
  5. Replies: 16
    Last Post: 06-27-2010, 04:16 AM

Posting Permissions

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