This week's book giveaway is in the Programmer Certification forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Welcome to the Ranch It is good to see correctly‑indented code.
Please give your classes proper names, not “sdsdd”.
Don't write new Integer(...). Simply write myList.add(k); The untime will automatically “box” that value to an Integer object.
What does line 29 mean? When is it possible for k to be negative? Why are you testing k in conjunction with the equality test? What is the condition controlling the else in line 32?
Do you mean you want to enter something from the keyboard and dependent on that entry you will execute or not execute the second half of the method? Have a look at this class; maybe this method will be useful.
But you shouldn't be executing half a method. That means the method is too long and should be divided up into something like this:-
Acetylsalicylic acid is aspirin. This could be handy too: