Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

please provide solution:  RSS feed

 
raghu ram
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CAN ANY BODY HELP ME OUT IN THIS PROBLEM.I WANT TO PRINT THE BELOW FORMAT
ON THE SCRREN.PLEASE HELP ME WITH THE LOGIC TO SOLVE IT

1
2 3
4 5 6
7 8 9 10
[ August 05, 2007: Message edited by: raghu rajan ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all please KeepItDown.

The simplest solution would be:


What does the first code you tried look like?

See also:
DoYourOwnHomework
[ August 05, 2007: Message edited by: Garrett Rowe ]
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raghuram vardharajan:
CAN ANY BODY HELP ME OUT IN THIS PROBLEM.I WANT TO PRINT THE BELOW FORMAT
ON THE SCRREN.PLEASE HELP ME WITH THE LOGIC TO SOLVE IT

1
2 3
4 5 6
7 8 9 10

[ August 05, 2007: Message edited by: raghu rajan ]


You need an int variable to store the number of rows you want to print. A main loop will check against exceeding this value.

Another int variable is needed to store the current value being printed (this will be incremented after each print).

And finally, an int variable is needed to store the current row being printed (incremented after each row is printed).

In printing a row you use a for loop - from 1 to current row #. The for loop will use System.out.print() and System.out.println().
 
raghu ram
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
smith can your procedure be applicable to n rows,such that if we
pass n=4
then we should be able to print
1
23
456
789 10 and if n=5
1
23
456
789 10
11 12 13 14 15
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, raghu ram. All you need to do is take the logic Red Smith has suggested and add a loop round it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!