Campbell Ritchie

Marshal
+ Follow
since Oct 13, 2005
Cows and Likes
Cows
Total received
248
In last 30 days
1
Total given
503
Likes
Total received
6150
Received in last 30 days
62
Total given
326
Given in last 30 days
10
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

That would appear to be the same question as here, where you have already got some help. Please don't ask the same quesiton twice; I am closing this discussion.
15 hours ago
Another way you could write that listener is like this:-
15 hours ago
You don't need an option pane for input on a GUI; you simply need a text field to enter the size in. Give it an accompanying label, “Size: range 3...14 please,” and parse the size from that field.
You can still use a Scanner on such a field:-Put the response to no int input in line 470 and the response to out of range in line 468. If you can't understand line 464, ask again.
You may wish to use an option pane to signal the error.
15 hours ago
The reason the outputs are not in any particular order is that the three Threads complete their “calculations” much faster than printing to the terminal, so they access System.out at any old time. This is a common finding when multi‑threading; the individual Threads run at different speeds and you cannot predict which will complete first.
16 hours ago
Don't post your email address; that will simply attract spammers.
We recommend you keep all discussions on the forum.
16 hours ago
Would you want a String in the first place? I remember when I was beginning I was given an exercise to print the individual digits in an int backwards, which was done with a combination of a while loop and the / and % operators. You can alternatively use those digits as indices to increment the values in your array.

Not an Android problem: moving to a Java forum.
16 hours ago

Steven Villarreal wrote:This method checks if there is not anything besides a number in the showInputDialog called userInput. It works but when I enter a negative number like -1  . . .

But you are not testing for negative numbers, nor throwing any exceptions. Make the option pane say, “must be in range 3...14,” and test for negative numbers.

Why are you using option panes for keybpard input? That is a very old‑fashioned sort of programming, which has been largely superseded by the use of Scanners.
Don't throw an exception and catch it in the same method. That is simply an inefficient implementation of if‑else. Do this, without using exceptions at all:-Formatting: make sure there is a space before each { and after if.
Don't prefix variable names with anything to denote their type of scope. Not iUserInput please, but something like sizeInput. Maybe requestedSize would be better still.
16 hours ago
I tried it on Java9 and got unpredictable output:-

java Question16Demo
27.18281828459045
31.41592653589793
Printed
^[[A

^C[campbell@... ~]$ java Question16Demo
31.41592653589793
Printed
27.18281828459045
^[[A
^C[campbell@... ~]$ java Question16Demo
31.41592653589793
27.18281828459045
Printed

The control characters are caused by my trying to run the program again; it seemed to print output but not in any particular order, and then keep running doing nothing.
17 hours ago
Welcome to the Ranch
23 hours ago

Ronniea Rox wrote:. . . Best Android Books:- https://abhiandroid.com/book

I only know one of those books mentioned on your sebsite, but I wouldn't call that particular book “best”.
23 hours ago

Ronniea Rox wrote:. . . I have also suggest some books for Java Android Tutoiral.  . . .

Is that your website? Otherwise, don't quote somebody else's website without fuller attribution.
We are not here to publicise your website. Should you wish to pay for advertising please contact us.
23 hours ago
Welcome to the Ranch

Please always say where such material comes from, to reduce copyright problems and to enable us to assess the original.
You are not specifying that your Set has to contain any particular subtype of Number, as you would with Set<E extends Number>, so you can accept anything that is a Number. Integers and Longs are Numbers, and null might be a Number. So all those add(xxx) calls are permissible under the semantics of generics.
Remembering that new Integer(86) creates a distinct instance every time it is called, remind us why 86 only appears once.