The way you wrote it, it is not simple. Welcome to the ranchAngelos Naoumis wrote:Very simple executable class
For me it worked. What makes you think it is not letting you input anything?Angelos Naoumis wrote:when i build and tried to run it, it did not let me input anything
Stephan van Hulst wrote:It's probably not related to your issue, but I don't think it's a good idea to create multiple scanners that read from System.in.
How do you run your application? What happens when you run it?
Liutauras Vilda wrote:
The way you wrote it, it is not simple. Welcome to the ranchAngelos Naoumis wrote:Very simple executable class
1. You don't need 2 scanner objects. You could change to:
2. Never ever omit curly braces (at least for now), even tho there are only 1 line of code within block. Your indented code should be looking similar to this:
For me it worked. What makes you think it is not letting you input anything?Angelos Naoumis wrote:when i build and tried to run it, it did not let me input anything
Campbell Ritchie wrote:Welcome to the Ranch
Since Scanners are not thread‑safe, there is the theoretical possibility that you could read the numbers in reverse order, but I think the chances of anything actually going wrong are very slim. You should not create two Scanners pointing to System.in because you only need one which you can reuse. And you always close a Scanner pointing to anything else but not if it points to System.in.
Why have you got everything in the main method?
Forget about saving time or RAM. You use as much time as you need. And memory is now cheap; you can buy more memory than you will need for less than we would spend going out to celebrate somebody's birthday.Angelos Naoumis wrote:. . . Is there any other way? I mean i would like to know how to save time and ram (this task is simple but a bigger one can profit from it)
All things are lawful, but not all things are profitable.
All things are lawful, but not all things are profitable.
Liutauras Vilda wrote:Never ever omit curly braces (at least for now), even tho there are only 1 line of code within block.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
You can use it when there is no information required from outside in order to create an instance of the class.Angelos Naoumis wrote:. . . Whats the point of an empty constructor?
Yes, but it is better to do that from a start, run, or similar method than from the main methodCan i call multiple methods from a launcher? . . .
No. As long as they are in different classes, the JVM will find the correct method. But don't mark those methods static.Your example will not compile because you have declared the same variable thrice.But the names of the classes are very confusing.Also do i have to rename run method in each class in order to load properly? run/run1/run2
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|