-
Help in making an output for this Graphic (newbie)
I'm newbie =)
I've made the code for the 1st and 2nd output but, my problem is i dont know how to do the codes for the 3rd and 4th. can anyone help me please? thanks so much my Friends!!!
Code Java:
1.
*
**
***
****
*****
import java.io.*;
public class Asterisk1
{
public static void main(String jpg[])
{
int n=5;
for(int x=1; x<=n; x++)
{
for(int y=1; y<=x; y++)
{
System.out.print("*");
}
System.out.println();
}
}
}
2.
*****
****
***
**
*
import java.io.*;
public class Ast1
{
public static void main(String jpg[])
{
int n=5;
for(int x=1; x<=n; x++)
{
for(int y=5; y>=x; y--)
{
System.out.print("*");
}
System.out.println();
}
}
}
the problem are these
3.
*****
****
***
**
*
4.
*
**
***
****
*****
-
Re: Help in making an output for this Graphic (newbie)
When posting code, please use the highlight tags to retain the correct formatting: [highlight=java].. your code here ..[/highlight]
You probably also need to include your output examples inside the highlight tags, because examples 3 & 4 are identical to 2 & 1 as posted. Posts here by default remove multiple spaces, unless put inside the tags.
-
Re: Help in making an output for this Graphic (newbie)
Draw the designs you want to print, look at where the spaces are and where the *s are.
Design code that will output the required number of spaces and the number of *s on each line.
Your current code just outputs *s, now you need some leading spaces before the *s.
-
Re: Help in making an output for this Graphic (newbie)
Search the forums or view the 'Similar Threads' box at the bottom of this thread.. This question has been answered 100 times before :)
-
Re: Help in making an output for this Graphic (newbie)
Code java:
1.
*
**
***
****
*****
import java.io.*;
public class Asterisk1
{
public static void
main(String jpg[])
{
int n=5;
for(int x=1; x<=n; x+
+)
{
for(int y=1; y<=x; y+
+)
{
System.out.print("*")
;
}
System.out.println();
}
}
}
2.
*****
****
***
**
*
import java.io.*;
public class Ast1
{
public static void
main(String jpg[])
{
int n=5;
for(int x=1; x<=n; x+
+)
{
for(int y=5; y>=x;
y--)
{
System.out.print("*")
;
}
System.out.println();
}
}
}
the problem are these
3.
*****
****
***
**
*
4.
*
**
***
****
*****
im posting via mobile. if 1st and 2nd combined with the 3rd and 4th
output it will just give you
a diamond shape.
-
Re: Help in making an output for this Graphic (newbie)
Have you solved it now? Your post doesn't really say?
-
Re: Help in making an output for this Graphic (newbie)
hi sir norms! sadly, not yet. hai... pls.
-
Re: Help in making an output for this Graphic (newbie)
What work have you done on the problem?
-
Re: Help in making an output for this Graphic (newbie)
ah just changing values of x and y and playing on increment and decrement. but fails me. do i need to add another system.out.print(); ? so that if a statement is true or false it will print an empty space? thanks for your time sir.
-
Re: Help in making an output for this Graphic (newbie)
Have you looked at the problem of what is being printed line by line?
What goes on the first line? Some spaces and some *s
What goes on the second line? A different number of spaces and *s
How does the number of spaces and asterisks change from one line to the next?
Is there a relationship between the line number and the number of spaces and the number of *s printed on that line?
-
Re: Help in making an output for this Graphic (newbie)
if you look at the 1st and 2nd output, mirrored view. thats what i need to do. i know you are trying to push me to make it for myself coz its too easy and i realy wanted to. but, the problem is its too hard for me. :-( im in my 2nd day of learning java.
-
Re: Help in making an output for this Graphic (newbie)
Part of your problem could be using the wrong variable names and no comments.
Here is the second assignment with comments and new names:
Code :
int nbrRows=5;
// Print on nbrRows
for(int row=1; row<=nbrRows; row++) {
// Print some stuff on this row
// Start with *s
// Fill the first row and then one less for each row after
for(int column=nbrRows; column >= row; column--) {
System.out.print("*"); // Print * in columns on this row
} // end for(column)
System.out.println(); // No more on this row, move to next row
} // end for(row)
Go back to post#10 and answer the questions I asked there.
-
Re: Help in making an output for this Graphic (newbie)
wow! you just make that so fast?! great! sir norms. my instructor might want the script to be as almost the same as what ive posted above... hmmm. i cant explain exactly since im not that good in english. hihi
-
Re: Help in making an output for this Graphic (newbie)
Quote:
Originally Posted by
Norm
Have you looked at the problem of what is being printed line by line?
What goes on the first line? Some spaces and some *s
What goes on the second line? A different number of spaces and *s
How does the number of spaces and asterisks change from one line to the next?
Is there a relationship between the line number and the number of spaces and the number of *s printed on that line?
Number of spaces and *'s change every new line. and i dont know what is the exactly statement or new line command for printing an empty space. i don't know how to make it print 4 spaces and then 1 * and in second line print 3 spaces and then 2 *'s.
-
Re: Help in making an output for this Graphic (newbie)
System.out.print(" "); // prints a single/empty space
Quote:
how to make it print 4 spaces
Look at the code you posted already. It prints a different number of *s on each line. Hint: it takes a loop
-
Re: Help in making an output for this Graphic (newbie)
Quote:
Originally Posted by
Norm
System.out.print(" "); // prints a single/empty space
Look at the code you posted already. It prints a different number of *s on each line. Hint: it takes a loop
Yes ir. i tried to add this already but nothing happens. ehehe! i dont know where to put it exactly. =(
-
Re: Help in making an output for this Graphic (newbie)
Do the project a small bit at a time.
Write down on paper the steps to print out the first line. See post #10.
What do you need to print for the first line? Some spaces and some *s.
Two parts:
One print x spaces: what is the code for that?
Two print y *s: what is the code for that?
How do you print a space? I showed you in post#15
Put that in a loop that executes x times to get x spaces.
Do the same for the *s.
-
Re: Help in making an output for this Graphic (newbie)
Quote:
Originally Posted by
Norm
Do the project a small bit at a time.
Write down on paper the steps to print out the first line. See post #10.
What do you need to print for the first line? Some spaces and some *s.
Two parts:
One print x spaces: what is the code for that?
Two print y *s: what is the code for that?
How do you print a space? I showed you in post#15
Put that in a loop that executes x times to get x spaces.
Do the same for the *s.
hmmm.. like for the statement of the x is false it will print space?
and then if the statement of y is true it wil print *s?
ohhh... =( need to get food im hungry.. my brain is not working.
Sir why arent you giving me the exact answer to this? you really want me to solve it? ehehe! woooshh... hard. hehe. thanks sir. (getting food)
-
Re: Help in making an output for this Graphic (newbie)
No. x and y are numbers. like 4 and 1 then 3 and 2 etc
Quote:
you really want me to solve it?
Answer me this question: Do you want to learn programming?
If so, you'll need to learn to think like a computer operates.
-
Re: Help in making an output for this Graphic (newbie)
Quote:
Originally Posted by
Norm
No. x and y are numbers. like 4 and 1 then 3 and 2 etc
Answer me this question: Do you want to learn programming?
If so, you'll need to learn to think like a computer operates.
i really do!
-
Re: Help in making an output for this Graphic (newbie)
-
Re: Help in making an output for this Graphic (newbie)
First do the steps I asked you to do in post#17
What do you need to print for the first line? Some spaces and some *s.
Two parts:
One print x spaces: what is the code for that?
Two print y *s: what is the code for that?
How do you print a space? I showed you in post#15
Put that in a loop that executes x times to get x spaces.
Do the same for the *s.
-
Re: Help in making an output for this Graphic (newbie)
as what you thaught me, this is how to print a space > System.out.print(" ");
what do you mean bout this Sir?
One print x spaces: what is the code for that? <<< for(int x=1; x<=n; x++) System.out.print(" "); ???
Two print y *s: what is the code for that?
-
Re: Help in making an output for this Graphic (newbie)
What happens when you compile and execute your code?
Quote:
print y *s: what is the code for that?
y is an integer, like 4. If you print 4 *s the printout would be: ****
You already have the code for that in your first two programs.
-
Re: Help in making an output for this Graphic (newbie)
another hint pls. ^_^
its hard to print spaces before the *s.