Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Produce Java code Output

 
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.]
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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
 
lowercase baba
Posts: 12838
52
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.
 
Evacuate the building! Here, take this tiny ad with you:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic