• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Produce Java code Output

 
Murphy Tai
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone [explain to me how to write] a code that accepts a size from the user and produces a diagonal output. Like so:

Output Console:
Size? 17
$$$*$$$*$$$*$$$*$
$$*$$$*$$$*$$$*$$
$*$$$*$$$*$$$*$$$
*$$$*$$$*$$$*$$$*
$$$*$$$*$$$*$$$*$
$$*$$$*$$$*$$$*$$
$*$$$*$$$*$$$*$$$
*$$$*$$$*$$$*$$$*
$$$*$$$*$$$*$$$*$
$$*$$$*$$$*$$$*$$
$*$$$*$$$*$$$*$$$
*$$$*$$$*$$$*$$$*
$$$*$$$*$$$*$$$*$
$$*$$$*$$$*$$$*$$
$*$$$*$$$*$$$*$$$
*$$$*$$$*$$$*$$$*
$$$*$$$*$$$*$$$*$

See the pattern.
Where '17' is the user input. Any integer can be entered into program to generate a diagonal-like output of dollar signs and asterisks.

[EFH: Translated into grownup language.]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

What have you got so far? Do you know how to write and compile a class? How to accept arguments on the command line? Print output?
 
Murphy Tai
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know all the basics of java. I just need a code that would produce the output outlined above using loops and nested loops.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Murphy Tai wrote:I know all the basics of java. I just need a code that would produce the output outlined above using loops and nested loops.

Um, this is a forum, NotACodeMill. ShowSomeEffort and ask a more specific question when you get stuck.

Recommended reading: http://catb.org/~esr/faqs/smart-questions.html
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try describing what you want to see in words. For example:

We should end up with 20 lines totals.
We should see 20 '*' characters on the first line, 19 on the second, 18 on the third.
After every third '*', print the current time in miliseconds

Once you can do that, you start translating it into code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic