• 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

Forcing horizontal display

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I force horizontal display of results of multiplication between numbers (for example)1 through 12... results are stored in a two-dimensional array and the requirement is that the display of those results is in a table... in the darkness of the command prompt... have tried typical escape character tricks, but they didn't trick the dark screen of DOS...
Imports allowed only from util...
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Gjorgi Var
Is it shown in the following?
1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 6 9 ...............
.................
Using two-dimensional array to store the above result?
 
Gjorgi Var
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it's more like this:
1 2 3 4 5 6...12
1 results result result
2 result...
3
4
.
.
12
Yeah, what a sloppy beginner...
[ April 09, 2004: Message edited by: Gjorgi Var ]
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if this answers your question, but you can display a two dimensional table as follows:

Be sure your DOS window is wide enough to hold a row of your array. This is controlled by the properties->layout tab of the icon for the MS-DOS window.
You can save screen width by using " " instead of "\t" but that means the columns won't always line up.
By the way, if you don't like the white on black color scheme, change it in the properties->colors tab
 
Gjorgi Var
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After compiling Mike's code (prevously put it in class framework and all that) I get NullPointerException (I guess for missing the "x[i][j]=i*j" part). But even after corrections both on the code and on the DOS window settings, layout is stil vertical...
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you notice where I used System.out.print instead of System.out.println? System.out.print prints and stays on the same line. System.out.println also prints but it adds a '\n' so the next output will go on the next line.
As for the NullPointerException, you said in your first note that you were printing from a two-dimensional array. You probably have a problem in setting up the array.
Remember that you must first declare a named reference to two-dimensional array objects, then create a two-dimensional array object consisting of references to one-dimensional array objects and point the reference to it, then create each one-dimensional array object and point the references in the two-dimensional array object to it, then assign your values to each element of the completed two-dimensional array. There are ways to perform these steps into fewer statements, but they must all happen.
Your textbook should have a good example. If you like, post your code and we'll give you our best advice.
[ April 10, 2004: Message edited by: Mike Gershman ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic