| | |
Please help me with the program code
![]() |
•
•
Join Date: Jun 2009
Posts: 13
Reputation:
Solved Threads: 0
I need to write a program to print the below pattern of * representing the alphabet X.
I am unable to print an X using asterisks in the post.
I hope you can understand the below explanation.
The X should have 7 rows - with three rows at the top and 3 at the bottom. Each row holds 2 *.
* *
* *
* *
*
* *
* *
* *
Please Help !!!!!!!!!!!!!!!
I am unable to print an X using asterisks in the post.
I hope you can understand the below explanation.
The X should have 7 rows - with three rows at the top and 3 at the bottom. Each row holds 2 *.
* *
* *
* *
*
* *
* *
* *
Please Help !!!!!!!!!!!!!!!
Last edited by shakeelahmed22; Jun 3rd, 2009 at 3:58 pm. Reason: unable to print an X with *
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
I need to write a program to print the below pattern of * representing the alphabet X.
I am unable to print an X using asterisks in the post.
I hope you can understand the below explanation.
The X should have 7 rows - with three rows at the top and 3 at the bottom. Each row holds 2 *.
* *
* *
* *
*
* *
* *
* *
Please Help !!!!!!!!!!!!!!!
Use code tags. It preserves formatting.
[code]
// paste *'s here
[/code]
Java Syntax (Toggle Plain Text)
* * * * * * * * * * * * *
•
•
•
•
Each row holds 2 *.
You should use a nested for-loop (a for loop within another for loop).
Last edited by VernonDozier; Jun 3rd, 2009 at 4:04 pm.
•
•
Join Date: Jun 2009
Posts: 13
Reputation:
Solved Threads: 0
The pattern is as below
Java Syntax (Toggle Plain Text)
* * * * * * * * * * * * *
A simple solution:
java Syntax (Toggle Plain Text)
int draw() { int pat[7][7] = { 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 }; int i, j; for(i = 0; i < 7; i++) { for(j = 0; j < 7; j++) { if(pat[i][j] == 1) { System.out.print("*"); } else { System.out.print(" "); } } System.out.print("\n"); } return 0; }
Last edited by Luckychap; Jun 3rd, 2009 at 5:27 pm.
When you think you have done a lot, then be ready for YOUR downfall.
Well, sure, except for three things:
1) it's C and this is the Java forum
2) If you are going to hard-code the whole pattern, why would you bother to use 1 and 0 to encode it just so you can translate it back with if() statements to the '*' you want to print? You may as well just put the asterisks in an array and print it in that case.
3) I would assume figuring out the loop logic is a goal of the assignment.
1) it's C and this is the Java forum
2) If you are going to hard-code the whole pattern, why would you bother to use 1 and 0 to encode it just so you can translate it back with if() statements to the '*' you want to print? You may as well just put the asterisks in an array and print it in that case.
3) I would assume figuring out the loop logic is a goal of the assignment.
Last edited by Ezzaral; Jun 3rd, 2009 at 5:30 pm.
•
•
Join Date: Jun 2009
Posts: 13
Reputation:
Solved Threads: 0
hey luckychap thanx 4 da reply...bt i m still having a problem wid it....
look this is what i tried
evryime i try 2 compile this program its displaying
']' expected
....i dont understand it...
what shall i do now????
n also i think ezzaral has a point when he says we can simply put the asterisks in the array n print it
look this is what i tried
java Syntax (Toggle Plain Text)
class pattern { void disp() { int a[7][7]={{*,0,0,0,0,0,*}, {0,*,0,0,0,*,0}, {0,0,*,0,*,0,0}, {0,0,0,*,0,0,0}, {0,0,*,0,*,0,0}, {0,*,0,0,0,*,0}, {*,0,0,0,0,0,*}}; for(int i = 0;i<7;i++) { for int(j = 0; j<7;j++) { if(a[i][j] == '*') System.out.print("*"); else System.out.print(" "); } System.out.println(); } } }
']' expected
....i dont understand it...
what shall i do now????
n also i think ezzaral has a point when he says we can simply put the asterisks in the array n print it
Last edited by Tekmaven; Jun 4th, 2009 at 3:15 pm. Reason: Code Tags
![]() |
Similar Threads
- Trafic signal control program code needed (C)
- New to C program code to calculate age (C)
- why this sample program doesen't work? (C++)
- Recursion Program/Code I'm having issues with... (Java)
- last section of code has to a static class (Java)
Other Threads in the Java Forum
- Previous Thread: Inverting value of boolean variable?
- Next Thread: JTable guidance needed
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






