• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Homework help

 
Greenhorn
Posts: 2
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I'm stuck on a question and I just need a hint on how to get the result she wants. Here's the question

Write and test a method that takes as parameter any positive integer n and prints the following.

The elements in the 1st row and column are all 1.
The elements in the 2nd row and column are all 2 (except for those in the 1st row and column).
The elements in the 3rd row and column are all 3 (except for those in the 1st and 2nd row and column).
And so on.

Example on next page.



E.g. n = 3 E.g. n = 5

1 1 1 1 1 1 1 1
1 2 2 1 2 2 2 2
1 2 3 1 2 3 3 3
1 2 3 4 4
1 2 3 4 5
 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bailey,

You can do that with the use of for loops. That is called "nested for loops" and they will be of the form:

BTW: with your 2 examples running together, I cannot actually tell just what it is that you are printing out.

Bailey Kufner wrote:Hey,

I'm stuck on a question and I just need a hint on how to get the result she wants. Here's the question
. . .

 
Les Morgan
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you get stuck, write the process out on paper in English, and modify it until you can walk through the description you made and create the desire outcome.

Bailey Kufner wrote:Hey,

I'm stuck on a question and I just need a hint on how to get the result she wants. Here's the question
. . .

 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bailey Kufner wrote:. . .
E.g. n = 3 E.g. n = 5

1 1 1 1 1 1 1 1
1 2 2 1 2 2 2 2
1 2 3 1 2 3 3 3
1 2 3 4 4
1 2 3 4 5

If you change the quote tags to code tags, the patterns become easier to read. The normal text and quote tags do not support multiple whitespace, but the code tags do. You can get extra space by writing
“       ”.
 
reply
    Bookmark Topic Watch Topic
  • New Topic