• 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Needing help with coding  RSS feed

Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have recently started a programming course and it is in java which I have never touched coding before and having problems trying to get it to function 100% correctly. Was looking for places which could possibly offer advice or suggestions on how can fix my code and make it function better.

This is the type of code I came up with but can't get the last part to function correctly or notice anywhere could fix up myself.
Use command line interface to ask the user to input the following(You will need to convert this from a string to an integer)

Perform an operation to determine how many of each item should be ordered to maintain the stock use command line interface to output the number of apples and oranges that need to be ordered.
This is what i am trying to accomplish. I have ran it and debugged it and can get numbers for everything except for the last part . if anyone can offer help would be appreciative
Sorry for long post/long code just at a wall with trying to solve it on my own
author & internet detective
Posts: 38921
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

I recommend using {} after your if statements to make it more obvious which code goes with the if.

For example, do you mean this? I think so, but it isn't what your code actually does.

What it does is:

Plus assigning to the same variable twice in a row doesn't seem necessary so it is like you are wiping it out.

For the last part, you can't subtract two strings. You are going to need to convert to int. One way to do that is Integer.parseInt(str)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!