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.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Need help with a code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So my problem is, that i need the second list to be optional, like, console asks if you want the second list or not, and i need it to always be one number, and i have no idea how.
 
Marshal
Posts: 66236
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!