Results 1 to 7 of 7
- 01-23-2013, 05:18 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
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.
- 01-23-2013, 05:20 PM #2
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!
- 01-23-2013, 05:23 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Re: Help please with the pyramid of letters!!!I need this project for tomorrow
CAN you just help me???
- 01-23-2013, 05:36 PM #4
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!
- 01-23-2013, 09:14 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Re: Help please with the pyramid of letters!!!I need this project for tomorrow
Is it better now?
- 01-24-2013, 03:30 PM #6
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!
- 01-28-2013, 03:44 PM #7
Similar Threads
-
Convert English letters to Tamil letters
By srinivasmallabathula in forum New To JavaReplies: 1Last Post: 10-20-2012, 02:39 PM -
Draw a pyramid
By MisterNikos in forum New To JavaReplies: 23Last Post: 04-02-2012, 01:44 PM -
Need Help With Some Pyramid
By lord raza in forum New To JavaReplies: 1Last Post: 11-07-2011, 01:03 PM -
pyramid
By Dashinator in forum New To JavaReplies: 8Last Post: 11-15-2010, 09:10 PM -
Please someone help me with this calculator...due tomorrow..
By jvpk4 in forum New To JavaReplies: 16Last Post: 06-27-2010, 04:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks