• 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

Pattern Display

 
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranch,
I want to display some pattern, condition for pattern is

user enter different numbers and the following should be displayed

for example user enters 2,1,3,5

so in first column 2 '0' will be displayed followed by 1 '0' in second column followed by 3 '0' in third column followed by 5 '0' in fourth column .

I have written a program for this but mine output is coming as horizontal I want to print in vertical



Enter the number
4
enter the different number4times
2
1
3
5
00
0
000
00000

Thanks
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you can only print horizontally, you have to flip your printing loops. Print each row before you go to the next. That means your outer loop should count rows, not columns.

Now, you may wonder how to know the length of the outer loop, if you don't know which column you are going to print. There are two solutions: either you iterate over the length of the longest column, and if a column is shorter than that length, it just prints whitespace, or you transpose your entire matrix, so it's now a[row][column].
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic