# a syed

Greenhorn
since Feb 02, 2019
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by a syed

Campbell Ritchie wrote:

a syed wrote:. . . I don't why the > appeared

Nor do I; I shall see whether anybody else has any ideas. That sort of thing has happened before

. . . it doesn't work

No, it doesn't does it?

You haven't, I don't think, explained what you are supposed to do in the dreaded words of one syllable (and I showed, just for the fun of it, that you can use words of one syllable). I don't think you have explained how to do it. Nor have you corrected the second half of your pseudo‑code; I only said the first half was correct.

Sorry man I'm new to this, can you give me the solution so I can try it and learn from it.
1 week ago

Campbell Ritchie wrote:

a syed wrote:. . .

this works

No it doesn't. Even if you remove the > symbols which have mysteriously appeared, you haven't tried it with inputs like “blank” “blankety‑blank” and 6. Or 6> like this: 6

I don't why the > appeared

here's my code:

its meant to return true only if the n characters are the same and if n is larger than the number of characters then it should return true if the shorter words are the same words.
but it doesn't work
1 week ago

Campbell Ritchie wrote:No. You are all right with the first part, You need to take the result of the first part and incorporate it into your loop.

public boolean equal(String s, String t, int n) {
// replace the following line with your implementation
for (int i=0; i<n; i++){ >
if (s.charAt(i) != t.charAt(i)){
return false;
}else if (s.length()<n||t.length()><n){ >
return true;
}
}return true;
}

this works
1 week ago

Campbell Ritchie wrote:Maybe this is what the assignment means:-

First, see if the two words are the same length.
Then go through the two words as far as you have been told to, and see if the char in word 1 at that place is the same as the char at the same place in word 2.
You get true if both tests pass; if you get one test to pass and one test fails, the whole thing counts as false.

Just in case you didn't believe it could be done in words of one syllable You need to make it read simply enough that even I can follow it.

is my pseudocode fine?

IF [Word1length]=[Word2length]
AND
Where i=1 i=i+1
IF Char(i)Word1=Char(i)Word2
return true

1 week ago

Campbell Ritchie wrote:For a start, you are getting confused with your if‑elses.

Also, more important, you are trying to write code before you have worked out what you are going to do. Your code looks as if you were guessing about the algorithm, not as if you who had thought it through and got the algorithm right. You can guess 1,000,000 different times and there is a very good chance of one of the guesses being correct. Or you can work it out correctly and get it right first time.

I understand what I have to do but I don't know how to implement it in java correctly. So where do I start?
1 week ago

Campbell Ritchie wrote:

sy ab wrote:. . . if this fine? . . ..

No. Look at the old sun style guide. You should write return s1.length() == ...;
And what happens when you try running ...equals("bind", "band", 5) ?
Try to organise your boolean expressions so they evaluate to true because that will make the code much easier to read than if the expression evaluates to false.
Always use the code button; because you are new (welcome to the Ranch ) I edited your first lot of code and doesn't it look better

I get true for bind band 4 which should be false.
what is wrong with m code?
1 week ago
How would I do this one, So far I've done:

public boolean lessThan(String s, String t, int n) {
for (int i=0; i<n; i++) {
if (s.charAt(i) != t.charAt(i)) {
return true;
}
}return false;
}
Im correct for the first 3 Bullet  but don't know what to do for the last 2.
1 week ago

Knute Snortum wrote:It looks like you will need a loop.  Have you learned about those?

Also, when you are tempted to write

if (something) {
return ture;
} else {
return false;
}

return something;

if this fine?

public boolean equal(String s, String t, int n) {
for (int i=0; i<n; i++){
if (s.length() != t.length() && s.charAt(i) != t.charAt(i)){
return false;
}
}return true;
}

Gives a correct output.
1 week ago

Tim Moores wrote:That looks like an exercise you should be doing in order to learn something. So: what do you have so far, and where are you stuck making progress? If you haven't started, what ideas have you had?

I've done this so far:

Which fulfils if both have the same length and the same characters. but how do I return true if the first n elements of the two arrays are equal, or, if either is shorter than n.
1 week ago
How do I implement this searching algorithm in java in here?

public boolean equal(String s, String t, int n) {

}
1 week ago

Adrian Grabowski wrote:Sure. At what point did you get stuck? Try creating a second box on the top of the first one manually, then you should be able to see the pattern.

Im not sure what to put in the while loop. I know if will start of like while(){} ~just not sure what to add in the brackets. apologies I am fairly new to coding.
1 month ago
can someone help me create a stack of boxes using a while loop?
attached is code for 1 box.
1 month ago