Suane Mane

Ranch Hand
+ Follow
since Jan 31, 2019
Suane likes ...
IntelliJ IDE Java MySQL Database
Lost in java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Suane Mane

Paul Clapham wrote:Or you can do what I do. Never use the value returned by either x++ or x--. Just use them as standalone expressions to increment a variable.

Of course if you plan to write certification exams you're sure to find this sort of question, so you'll have to know the difference between the two. But once you've passed the exams, don't ever use them again. Generations of programmers who have to maintain your code will thank you.

Lol I'll keep that in mind. Yeah I'm just checking my exam answers now so I can disappoint myself before official results come out.
2 weeks ago
Alright, guess I'll have to get used to it then. Thanks!
2 weeks ago

So the index of "#" is 5. Then n is 5. Then n+1 = 6.
The length of string s is 9.
From what I know, s.substring (x, y) means this substring will contain elements from string a from start point x until BUT NOT INCLUDING end point y.
So this should be from 6 to 9, not including 9, thus from 6 to 8. So from index 6 (which is the first "a") until the end of the string (since s.length denotes max length of it). So that means from index 6 until the end of the string but not including the very last element. That would make the output "aa" but when I checked it, it showed "aaa".
I don't understand why.
2 weeks ago
This is the fragment:

Apparently the output is 5. I don't understand why.
y+=z is 5.
x++ is 2.
5/2 should be 2.

The only explanation I could think of is that x is incremented after the division and it's only 5/1 = 5 then.
But that doesn't make much sense to me. Can you not ever use "x++" as a whole value? If you want to do operations with the result of the statement "x++" is it never possible to do so by just typing x++? Does it always have to be saved into a variable and then do operations through that variable instead so you make sure the value is incremented for the operation you need and not after or do you always need to use ++x instead of x++? This bugs my brain so much.
2 weeks ago

fred rosenberger wrote:Not to beat a dead horse, but by your logic, modulus would never return anything but zero.  12 divided by five would be 2.4, so 0 is the remainder.

15 divided by 8 is 1.875, so zero is the remainder...


Modus, by definition, is the leftover after integer division.  so 2 goes into 1 exactly zero times, with one left over. just like 5 goes into 12 two times, with two left over...

No no like I keep saying, it was the fact the dividend was smaller than the divisor which confused me. Your examples are easy for me to make sense of, but anything with smaller dividend will result in '0.something' and since it's int division, result is just 0. For some reason the result being 0 just confused me about how to process the remainder. Nothing to do with the case of float or not. Just the fact result is 0, whether it's 0.n or just 0.

And I understood it from Dave's explanation. I'm not arguing anything. Not sure where you're getting at.
I just had some confusion about the logic of modulus in cases as such with lower value dividend and higher value divisor. But it's cleared now. I'm not arguing my logic was good. On the contrary, was trying to work out what's wrong.
I get it now - any int division with smaller dividend will yield a remainder equal to the value of the dividend itself.
1 month ago

How come this makes x and y not only the same value but the same object too? Does x = y automatically convert x into the same object as y? I thought this was only used to assign values not merge objects with one another.
1 month ago

Liutauras Vilda wrote:I think Dave gave an info, that the division is based on how many whole numbers fit. 3 % 2 as in this case, how many 2's fit to 3, so you divide 3 / 2, you get 1 and remainder 1, so you are correct on that one. And now if you get back to your initial example 1 % 2, how many 2's fit to 1? 0. You don't take fractions.

Yeah, I know there's no fraction in int division. I knew that from the start and still didn't help me understand remainder in any way whatsoever. How many 2s fit in 1 = 0. Just that further than that, I took it as being completely remainder 0. It was confusing.
1 month ago

Liutauras Vilda wrote:
But you are not dividing, you use modulus operation in actual question.

What would be 3 % 2 according to you?

In order to find the remainder you need to divide. So you are dividing even if the result required isn't the result of the division. 3%2 would have a remainder 1, yes.

Dave Tolls wrote:0.5 is not a whole number, so 1 divided by 2 is 0 remainder 1.
So the modulus is 1.

I think I get it... I think. So the division going on has to be int division. I did think of that and tried to look at it from that perspective but still couldn't get where the 1 was from because I thought 1/2 would be 0 and then you get no remainder. I need to brush up on what remainder actually means I guess. Got confusing with smaller dividend.
Thank you!
1 month ago
It's a short and simple question but it's baffling.
Why does 1%2 output 1?
In mathematical logic it should not. 1 divided by 2 is 0.5. Which means there is 0 remainder. You don't have any remainder when dividing 1 by 2. How can java output remainder of 1 then?
1 month ago
Got it now! So it's the same thing, just using a known string.
One thing is still confusing though - line 3: String c = x.substring(i, i + 1);
Doesn't this mean you are adding elements to string c from string x? Whether or not you print them, they are added. So this loop runs 3 times.
->First adding "a" to c, not printing
->then adding "c" to c, printing string c
->then adding "e" to c, not printing.

At the time of print, substring c has values "ac". Why then does print output only "c"?
1 month ago
I have this program fragment that confuses me a bit:

To my understanding the contains syntax is as follows:
stringx.contains("valuetobesearchedfor") - checks if valuetobesearchedfor is present in stringx and returns true if it is
I have not actually seen an example of how to use the opposite of contains to check if something is NOT contained in string, but I imagine it would work like:
!stringx.contains("valuetobesearchedfor") - then it would return true if the valuetobesearchedfor is NOT present in there

So what is up with the syntax in my fragment? (It's from exam papers, preparing for exam in 2 days... not going great lol)
Why is the value to be searched for placed before the string to search in? Why are the places reversed? Makes it seem like you're checking to see if "aeiou" has the value of c in it rather than the other way around.
So is this line asking if any of the characters "aeiou" are NOT contained in string c then you print string c or if any of the string "aeiou" is contained in c then you print?

Also the result is confusing. Apparently the output should be c. But during each run of the for loop you add elements from string x to substring c and then only print string c when condition is met. But in the end when condition is met, you still have to print the entire string c, which should be "ace" but that's not even an option on the paper. I'm so confused.
1 month ago

Swastik Dey wrote:try this

What does this do? Add elements to position [0][0], [0][1], etc? I'm supposed to read the words from file, not add them manually.
1 month ago
Any advice on how to actually search through the grid and finalise my project in the next 40 minutes? lol
1 month ago

1 month ago
Yes. It has to read each word from the words.txt file and search for each word in the grid. If the word is found, it has to print something like "word: row 4, position 1" to identify where in the grid the word was found.
1 month ago