######
#####
####
###
##
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
######
#####
####
###
##
######
#####
####
###
##
We've established what the goal is, that's good. Now it's time for you to tell us how far you've gotten with it and perhaps you want to ask a question about a specific part you're currently stuck on?
Tim Driven Development
public class pattern {
public static void main(String[] args) {
for (int row = 6; row >= 2; ++row){
for (int col = 1; col <= row; --col){
System.out.print("#");
}
System.out.println();
}
}
}
Does that do what you need?
Also, it's advisable to use code tags around your code to make it easier to read. For example, here's your code again with code tags.
It looks a lot better right?public class pattern { public static void main(String[] args) { for (int row = 6; row >= 2; ++row){ for (int col = 1; col <= row; --col){ System.out.print("#"); } System.out.println(); } } }
Now, does that code do what you need it to? What's the output of it?
Tim Driven Development
ok..thanks, the output is terrible.... it shows unending #'s.
You need to work out the logic first.shows unending #'s.
How many lines need to be printed?
What logic is needed to stop printing #s after the required number are printed for the current line?
How many #s are printed on each line?
How does that compare to the number printed on the previous line?
If you don't understand my answer, don't ignore it, ask a question.
Capture.jpg
above pic is a screenshot of my output..
pls ..i have no idea how the code interconnects with the pattern.....It's better if someone(who knows) can give me the code........I want following output...
######
#####
####
###
##
Sorry, we don't provide code.
You need first to work out the logic.
Consider these points:
how many lines need to be printed? Use a loop for the required number of lines.
the loop control variable normally increases, but it can also decrease. Going from 0 to 5 and from 5 to 0 gives that same number of loop iterations.
Next how many #s are to be printed on the first line?
Then how many on the second line? Hint: one fewer. fewer implies subtracting from a counter
Your code looks close. Make sure the loop variables are changing value in the right direction: increasing or decreasing as is required.
If you don't understand my answer, don't ignore it, ask a question.