Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display a pattern

 
Alireza Bahmanpour
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I had a simple question. I just needed to write a code to display the following pattern. I know it is easy, but the thing is, I am an absolute beginner (just started using java less than a week ago). So please don't laugh if its too easy. Here's the pattern:

The code I wrote is:

But this code displays the pattern wrongly, I don't know how I should change it to show the right thing

Thanks
 
Henry Wong
author
Marshal
Pie
Posts: 21207
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this code displays the pattern wrongly, I don't know how I should change it to show the right thing


Well, it would help if you post in the right forum. This forum is for Java beginners -- and BTW, you program isn't Java.

Henry
[ October 24, 2007: Message edited by: Henry Wong ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not Java code -- I'm not quite sure what it is, honestly!
 
Alireza Bahmanpour
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is a Groovy code (a new programming language, probably haven't heard of it, we just started doing this for the first time in uni). It's very similar to Java, in fact it's all based on java, with some added facilities. But even if you give me a psuedocode it would help.
 
Henry Wong
author
Marshal
Pie
Posts: 21207
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Groovy is a scripting language -- and it goes into the object orient scripting forum.... not here. Anyway....


I won't give you the answer, as this is a homework problem. But here is a hint...

Keep in mind that there are spaces too (Just because you can't see them, doesn't mean that they don't exist). You need to modify the program to print both the "*" and the spaces on each line. If you just print the "*", you will be left justified.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic