![]() |
|
#1
|
|||
|
|||
My first Java Program (Desperate for Help)Hi,
This is one of the examples of the java program that im trying to write. I am very new to this, can anyone help me with this java program, i cant get my head around this, any help would be very appriciated. Thanks. Here is the question: Write a program in java, using loops (this program may require multiple loops) to print the following pattern of stars: (i cant get the shape in here right but it needs to be in a diamond shape not triangle) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * There are 1, 3, 5, 7, 9, 9, 7, 5, 3 and 1 stars in each of the corresponding rows. |
|
#2
|
||||
|
||||
Re: My first Java Program (Desperate for Help)hi Skyer..
Welcome to GIDForums.. You have almost done your program except that: You have to print spaces(blank character) before you print * in every line. so design a for loop where you can print spaces as required so that you may obtain the diamond shape. so for the first line, you should print (n-1)/2 number of spaces and so on where n is the number of lines you want to print whether it is even or odd. Bye, Paramesh |
|
#3
|
|||
|
|||
Re: My first Java Program (Desperate for Help)I am very new to this can anyone give me the code to get that diamond shape pls? Thanks....
|
|
#4
|
||||
|
||||
Re: My first Java Program (Desperate for Help)hi Skyer,
Here is the algorithm i have used for the program: 1. The program is divided into three parts. -> one part to print the top portion of the program, -> one to print the middle line of the program(if the number of lines to be printed is odd) -> and the last part to print the bottom half of the program. 2. To print the top and bottom portion: ---> You have to print n/2 lines. make a variable i to vary from 0 to n/2 in a loop. ---> In each line you have to print spaces and asterisk. So we need two loops each. 3. To print the middle line, we must print n asterisks. thats all. This must be printed only if n is odd. Here is the program. This program works with both odd and even number of lines. n is the number of lines to be printed. You can vary n and see the output accordingly. Please read the comments at the end of every line for understanding the program. JAVA Code:
If you have any doubts, please post again to clarify. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#5
|
|||
|
|||
Re: My first Java Program (Desperate for Help)Hey Paramesh,
Thanks alot, that was very useful Cheers |
|
#6
|
|||
|
|||
Re: My first Java Program (Desperate for Help)hey paramesh, i need your help...I dont know wht is the code for the "send" button in my prog....i have a prog where i have to write a prog for an email message..i have the text boxes but dunno wht to put the code for "send " button...if u can tell what code to use it will be helpful.....
|
|
#7
|
|||
|
|||
Re: My first Java Program (Desperate for Help)hey Paramesh,
I have listed the code info under java... |
|
#8
|
|||
|
|||
Re: My first Java Program (Desperate for Help)for a button...
JAVA Code:
hope this helps you see how to add an action listener, and differiciate between them by just adding the same actionlistener to the different buttons... any questions reply Justin |
|
#9
|
|||
|
|||
Re: My first Java Program (Desperate for Help)thanks justin......i wanted to ask u somthing esle too...how u write the code for J panel?????and wht are components in the program,..ne examples????
|
|
#10
|
|||
|
|||
Re: My first Java Program (Desperate for Help)umm, I dont fully understand, I wrote an example of a JPanel above,
and the components in a JPanel can be anything... Images,JButtons,additional JPanels, JFrames(for popups),JTextFields,JTextAreas,etc... Justin go to sun.com and look at the api for java 1.5.0 and you can look up component and you'll find everything... __________________
Justin |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 12:04 |
| [TUTORIAL] Calling an external program in C (Linux) | dsmith | C Programming Language | 4 | 22-Apr-2005 13:30 |
| Made program in Java, trying C++ now, file i/o problems | technickel | C++ Forum | 4 | 19-Feb-2005 00:32 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 07:10 |
| calling a java program from C | Magicman | C Programming Language | 3 | 20-Oct-2004 07:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The