Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

how to print data in table form?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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: 6772
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
As Carey suggested, increment the year variable inside the loop.

Consider the following code:



 
Marshal
Posts: 67464
257
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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:-
  •  
    Marshal
    Posts: 6643
    177
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
    • 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.
     
    I once met a man from Nantucket. He had a tiny ad
    Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
    https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!