Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Nik Recort

Greenhorn
+ Follow
since May 13, 2018
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
17
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nik Recort

Ehm... Sorry, I missed the 2 again. Here it is:

1 year ago

Carey Brown wrote:I know you can't edit the post but you could re-post the entire class. Re-posting is often needed just because several people make suggestions and it's hard to visualize which changes you made and how you made them, so, a re-post puts us back in sync.



All I wanted to correct was the question in the first post where I used the wrong array name: args2 instead of args. So I guess the code can remain the same:


Many thanks again!
1 year ago

Carey Brown wrote:I'm assuming you've built a rudimentary class with a main() method in order to run your snippets. It would be helpful to us to see your whole class so that we can see for ourselves what you are doing with "args" vs "args2".


You're perfectly right, that was my mistake, args and args2 meant to be the same array. Unfortunely I cannot edit the post. By the way, it is from an example I have found on the OCA Study Guide. I just copied it onto Eclipse to check it, as it was not clear for me.

Campbell Ritchie wrote:What you are doing when you assign the two elements of your array in lines 2‑3 is creating new arrays and putting them in the two locations in your outer array, so, yes, what you thought seems to be correct.


Thanks a lot, this helped me a lot!

Campbell Ritchie wrote:You would do better to import java.util.Arrays, and use this method, or this method for simpler cases.


I'll definitely have a look. I knew of such methods, but I haven't used them much, to be honest.

So I assume both lines (2 and 3)

refer to index 0 and 1 of the outer array, the one of length 4 in int [][] args2 = new int [4][]?
1 year ago
Howdy folks =)

I have a few indecisions, so I hope you can help me.



I have tried to use the print command to check the evolving of the situation, like this:



and it prints:



If line 1 declares and initializes an array, what do lines 2 and 3 do?

args2[0] = new int [5]; and args2[1] = new int[3] add two different ints to index 0 and 1 of the array, or do they add new arrays of length 5 and 3 respectively?
1 year ago
My apologies, I have found this same topic here on the forums. I think you can delete this post.

Thanks anyway =)
2 years ago
Hi wonderful people!

Studying String objects immutability I came across an example, this one:



The output is 12.

I understand the difference between concatenation and addition, but can you explain me why the result is 12 and not 123?
2 years ago
Ok folks, thank you all very much for your time. I'll dig deeper into it, and in case return to it later when I know more, if I cannot make it work now.
2 years ago

Junilu Lacar wrote:TIP: Use the Preview button before posting a message so you can see the line numbers in the code that you post inside code tags. Then you can reference the correct line numbers.

You wrote:I get errors in line 19 and 20


... actually, lines 11 and 12 in the code you posted.

You wrote techniques.size instead of techniques.size().

And again, you might want to use java.util.Random instead of Math.random(). The code is much clearer when you use Random.



You are right. I was mistaken again. And I wrote line 19 and 20 because I deleted the comment lines above the program before posting it, without checking properly before hitting that post button. Thanks for letting me notice.

I am a bit lost, this is what I think you told me to add:


Now it gives me errors at lines 7 and 15.

Is it still convenient to add this line?
Sorry if I sound repetitive, but I don't have much of a grasp on Java, yet.
2 years ago
As I said my goal was to print a random element from the arrayList, in this case one of the two elements present (I know, maybe they are too few). I have studied so far that if you want a container that automatically accepts new elements without worrying about setting its size, arrayList is ideal.

I have tried this, which worked for normal arrays (I have corrected and tried it again to be sure before posting, I have also removed the capital letter from "techniques):



But I get errors in line 19 and 20.

And, by the way, what is the error in assigning an element of the array to a <String>? Aren't <String>'s, in this case, elements of the arrayList?

Oh, and in this case I want to use an ArrayList to play a bit with it, and get used to it. You know, I still need to write a looooot of programs to get used to it =).
2 years ago
Hi folks! How're you all doing? I have a simple question: how can I choose a random element from an arrayList? This is what i wrote:



When working with normal arrays I use to generate a random number using Math.random() (which choice interval depends from the length of the array itself), and print out the array element which index is equal to the random number. But here it doesn't seem to work.

Can you help me?
2 years ago
Wow that's a lot of info, thank you folks! It's very cool that you can write a code in so many and different ways. But to understand them all I suspect that i need to keep studying a bit more xD.

I am definitely taking notes tho, so I can come back to these examples as soon as I understand more about this wonderful programming language!
2 years ago