473,382 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to format my output to print exactly 20 values per line

I am writing a program that will print values that are divisible by 2,3,5 and will not print values that are divisible by 7 or 11. I've managed to get my output to print all the correct values but in one long row. Any tips how to break this massive row into rows of 20?
Nov 5 '13 #1
1 1382
Nepomuk
3,112 Expert 2GB
You could have a counter which is incremented each time you print a number. Then when this counter reaches 20 you set it back to 0 and call
Expand|Select|Wrap|Line Numbers
  1. System.out.println()
An further (and slightly more elegant) solution would use the counter you're probably already using, assuming that you're printing the values in a for-loop. You can check whether your current counter is divisible by 19 (or 20 if you start with 1) and if so print a new line. This can be done using the modulo operator (%).
Nov 5 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Michael Krasnyk | last post by:
Hi, How can I print variable values by their names? For example: import sys for str in dir(sys): print str Will be printed only variable names, but I need values from list of variable...
2
by: vj | last post by:
How to print a new line character . Is it chr(13) || chr(10)?
13
by: Vinu | last post by:
hai i have a problem i con't able to print the values of argv int main(int argc, wchar_t* argv) { return o; }
4
by: newbiecpp | last post by:
How can I format output string. For example, when I use: Console.WriteLine("12345") I want to output like " 12345", i.e., I need set width is 10 and align at right. How can I do it. ...
2
by: D. Shane Fowlkes | last post by:
I have a couple of fields in SQL Server which are defined as "Money". One is "Quantity" and the other is "Unit Price". Unit Price I can understand being defined as "money" but I'm not sure why the...
1
by: lorirobn | last post by:
Hi, I have a report that has a query as its record source. The query picks up records from a table that meet certain criterion. The report then counts how many records there are for each key...
1
by: Wayne Deleersnyder | last post by:
Hi All, I was going to write and ask if someone could help me fix the formatting of my output for hash values, but I believe I got it right now. But, because I couldn't find any website or...
0
by: kimmelsd33 | last post by:
I am adding to my software. I have placed about 30 checkboxes on a form. Based on which checkboxes are selected, I want to print the values to a tab delimited text file. For instance, the first...
4
by: AnagJohari | last post by:
I m not able to understand how i print the values of predefined symbolic constant. i have to print the values of _lINE_ The line number of the current source code line (an integer constant) _FILE_...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.