The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
I think I have already told him that.Stephan van Hulst wrote:. . . What formula can you think of that when you plug in any number between 1 and 10, yields 0? And yields 1 for any number between 11 and 20? And 7 for any number between 71 and 80?
I hadn't noticed because I couldn't read the code You can also use ...new Scanner(Paths.get("/home/campbell/myNumbersFile"))... or similar.. . .
Use Files.newBufferedReader(Path) to access files, not the FileReader class.
Stephan did use try with resources, and you can read more about it in the Java™ Tutorials.Close your resources when you're done with them. You never close the histogram file. You can do this by using a try-with-resources statement.
I had a different way to add the *s, which goes to show there are often several different ways to achieve the desired result. And sometime even several different good ways to do it!. . . Don't repeatedly concatenate to a string inside a loop. Instead of using an array of String, use an array of StringBuilder.
Another Java™ Tutorials section. The enhanced for loop (also called for‑each) is best if you are iterating the whole of a data structure in the normal (=forward) direction and in a read‑only fashion. Which you are doing here.. . .
Don't use a for-loop with index to iterate through all elements of an array or collection. Instead, use the enhanced for-loop.
I think Stephan would like you to complete the code where he threw the exceptions.[list]Don't put all your logic in the main method. The object oriented approach is to create a HistogramBuilder class that encapsulates your string builders. . . .
There are three kinds of actuaries: those who can count, and those who can't.
Tim Holloway wrote:Welcome to the Ranch, Cam!
Two things, though. We would prefer that you not post screenshots. They often don't display well and are hard to read and they eat up a lot of storage space on our servers. Where possible, copy-and-paste actual text. Our "Code" tag button can be used to wrap markers around the source code (or XML or SQL or other pre-formatted text).
Also, it looks like you may have cross-posted this question to StackOverflow. As a courtesy, please tell people when you do that, since often a question is being answered 2 different ways in 2 different places and people both here are there (and those who visit both) can get very confused.
Thanks!
What are you doing in my house? Get 'em tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|