print pattern like the fllowing using loops structure:
.........
........
.......
......
.....
....
...
..
.
--- Update ---
class Exercise4{
public static void main(String args[]){
int a =9;
while (a>0){
System.out.println(".");
a--;
}
}
}
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.
print pattern like the fllowing using loops structure:
.........
........
.......
......
.....
....
...
..
.
--- Update ---
class Exercise4{
public static void main(String args[]){
int a =9;
while (a>0){
System.out.println(".");
a--;
}
}
}
What does that code do?
Can you write out, in words, what the pattern is?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
You could try a string array containing every stage of the dot pattern and having a for loop cycle through the elements.
Hint: what you want to do is a very simple version of a histogram: https://en.wikipedia.org/wiki/Histogram
Hint: the number of dots and the number of lines are a function of a related loop iteration limit.
Hint: start with a method that takes two parameters, and prints a single line of n characters.
(It strikes me that this is an excellent intro Coding Golf exercise. If I leave out all readability I get something like 190 chars. But I'm actually making a method call, which eats up lots of space. 146 with no method call, but still using readable looping. This is like 40 VM instructions.)
Last edited by jdv; August 5th, 2014 at 10:56 AM.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!