Hi guys! I'm working on nested for loops in computer science at the moment, and am stuck on this one lab! I have to print out a picture of a rocket, but there's just so many symbols it's confusing me. Here's the link to the page:
http://cyfair3.schoo...jects/Lab17.pdf
The lab that I need, Lab17E, is at the very bottom. Thank you!
6 replies to this topic
#1
Posted 19 January 2011 - 08:33 PM
|
|
|
#2
Posted 20 January 2011 - 06:48 AM
The basic idea is that you need to divide the rocket in triangles and try to get the pattern. even the spaces need to be considered in terms of the triangle.
hope that helps you
hope that helps you
#3
Posted 20 January 2011 - 08:26 AM
90 points for
Anyway, the nose / tail is fairly simple:
If you did the previous exercises, you propably know how to do the 3 parts separately:
You then just have to cut and paste the 3 inner loops in 1 outer loop.
Like
Resulting in:
The body is slightly harder.
Will try to write some code tomorrow.. :P
******* ****** ***** **** *** ** *And only 100 for the rocket ?! :O
Anyway, the nose / tail is fairly simple:
/**\ //**\\ ///**\\\ ////**\\\\ /////**\\\\\ //////**\\\\\\ ///////**\\\\\\\ ////////**\\\\\\\\ /////////**\\\\\\\\\
If you did the previous exercises, you propably know how to do the 3 parts separately:
/ // /// //// ///// ////// /////// //////// /////////
** ** ** ** ** ** ** ** **
\ \\ \\\ \\\\ \\\\\ \\\\\\ \\\\\\\ \\\\\\\\ \\\\\\\\\If you have these 3 double loops, you'll notice the outer loop is the same with all of them.
You then just have to cut and paste the 3 inner loops in 1 outer loop.
Like
88888881 88888812 88888123 88881234 88812345 88123456 81234567 12345678consist of
8888888 888888 88888 8888 888 88 8and
1 12 123 1234 12345 123456 1234567 12345678
Resulting in:
for( int i=0 ; i<8 ; i++){
for( int j=0 ; j<7-i ; j++ ) {
System.out.print("8");
}
}
for( int i=0 ; i<8 ; i++){
for(int k=0 ; k<i+1; k++){
System.out.print(k+1);
}
System.out.println("");
}
And you just put both inner loops together:
for( int i=0 ; i<8 ; i++){
for( int j=0 ; j<7-i ; j++ ) {
System.out.print("8");
}
for(int k=0 ; k<i+1; k++){
System.out.print(k+1);
}
System.out.println("");
}
The body is slightly harder.
Will try to write some code tomorrow.. :P
#4
Posted 21 January 2011 - 12:16 PM
Don't write the code for him man. Look, as code_analyst said, you look at the output, divide it into logical components and solve each task individually leading to the whole. Consider the rocket nose cone. You need one for loop to loop through each display line. Now ask yourself about how you will display the spaces, the slashes, and the astrix. How does the number of each correspond to the line you are on. You could probably do this with just a single for loop even.
#5
Posted 21 January 2011 - 01:42 PM
Thank guys! I guess I just need to look at the smaller picture. I will give it a try :)
#6
Posted 21 January 2011 - 01:44 PM
sam_l said:
Don't write the code for him man. Look, as code_analyst said, you look at the output, divide it into logical components and solve each task individually leading to the whole. Consider the rocket nose cone. You need one for loop to loop through each display line. Now ask yourself about how you will display the spaces, the slashes, and the astrix. How does the number of each correspond to the line you are on. You could probably do this with just a single for loop even.
I didn't write any of his code, did I?
#7
Posted 03 February 2011 - 11:21 PM
can someone help me in making the code for this output? but the lines are composed of asterisk(*). Thanks!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









