Carey Brown

Saloon Keeper
+ Follow
since Nov 19, 2001
Carey likes ...
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
Forum Moderator
Carey Brown currently moderates these forums:
Cows and Likes
Cows
Total received
56
In last 30 days
0
Total given
2
Likes
Total received
1039
Received in last 30 days
20
Total given
127
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carey Brown

You might find the List#addAll() method to be useful. You can use it to make a new list but the contents of the new list will refer to the same objects of type "Long". Having the same reference to a Long is not a problem because a Long is immutable and cannot be modified.
19 hours ago

Jonny Balcon wrote:It is a textbook exercise and it is  requirement I should execute a deep copy.


Can you tell us the source of the exercise and exactly what the requirements are?
19 hours ago
Why do you think you need a "deep copy"? Or, for that matter, any copy at all?
1 day ago
Please UseCodeTags.

First question: does it compile?
1 day ago

Bill Platt wrote:What I want to do is remove the asterisks so that it reads as:

Warning! Problem detected!

6 days ago
Close. It should be:

6 days ago

Tim Moores wrote:I see, what you're asking is how to obtain the CPU and memory usage info for a chosen process. I'm not a Windows expert, but this discussion has a number of starting points on how to do that.

Discussion is from 2008. Perfmon.exe is still available in Win-10 but is a GUI with no API as far as I can tell. They also mention WMI which doesn't run on Win-10.

You'll need something with an API or at least log files.
1 week ago
You need some structure or Collection that represents the "state" of your bag. A part of the state needs to identify all the items in the bag at a given point in time and their sum weight and sum cost. You start out with an initial state for an empty bag.

You enter your recursive method with a state.
You look to see what you can add to the state that will not exceed the weight.
If that state has been tried before, return null.
If it is the exact weight, see of the cost is less than the last state that had the exact weight, then return the state.
If it is less than the weight, take the new state and pass it to the next call to the method.
If it is greater than the weight, return null.

The answer will be returned as you unwind the recursion back to the original call.

There are some subtleties not mentioned here, like, "almost" exact weight, but this is the general gist.
1 week ago

Knute Snortum wrote:...An entire table might be List<MyClass>.


Or a part of a table as returned by a query.
List<MyClass> results
As returned from a query "SELECT * FROM mytable WHERE something_is_true ORDER BY some_column"
1 week ago
Seems like the requirements are open to interpretation. All keyboard input comes in as characters.
  • You could get them as a list of numbers entered on a single line using Scanner#nextLine(), but then you'd have to separate then numbers and take each number (String) and parse it into an int (using Integer#parseInt()) for processing.
  • You could use Scanner#next() to split the numbers into individual Strings but then you'd still have to parse them into ints.
  • You could use Scanner#nextInt() which both splits the numbers and parses them into ints.


  • The last approach would be my preference but it depends on how you interpret the specs. With the last approach you end up with a list of ints that you can sum and count for your average but you'd have to print them to the display, which is trivial.
    1 week ago
    Sounds like an editor issue, not a Java issue.
    1 week ago
    What you are doing in your loop is:
    Read [0]
       Print [0], Print[1], Print[2], Print[3], Print[4], Print[5]
    Only [0] has been read so far so the others will be null.
    Next time you
    Read [1]
    Now when you print, [0] contains your first read, [1] contains your second read, all the others are still null.

    Why not just read "a String" and then print "a String"? No need for arrays.
    2 weeks ago
    What output were you expecting?
    2 weeks ago

    You are testing with hasNextLine(), but in the loop you're not calling nextLine().
    You also need to close the Scanner when you're done with it.
    2 weeks ago
    This is not doing what you think it's doing.
    i=i++
    Either use
    i = i + 1
    i += 1

    or best
    i++
    2 weeks ago