• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

how to print data in table form?

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was wondering how I could make a table that looks like the picture attached using for loops like in my program which I've added below:



Screen-Shot-2020-02-09-at-10.30.57-PM.png
[Thumbnail for Screen-Shot-2020-02-09-at-10.30.57-PM.png]
 
Saloon Keeper
Posts: 9556
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll have to do it with a single loop. You could add a 'year' variable to the loop which you increment, or you could calculate the year before the print statement.
 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Carey suggested, increment the year variable inside the loop.

Consider the following code:



 
Marshal
Posts: 76397
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • 1: Find out about System.out.printf() and the % tags.
  • 2: You can initialise and increment multiple loop variables in a for loop:-
  •  
    Sheriff
    Posts: 7113
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tomislav Brzica wrote:As Carey suggested, increment the year variable inside the loop.

    Consider the following code:


    Thanks for your contribution.  Just so you know, in the Beginning Java forum, we try not to provide a complete code solution until the OP does.  This is so the OP can benefit from learning.
     
    Carey Brown
    Saloon Keeper
    Posts: 9556
    79
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
     
    Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic