Need help writing a public method!


#1

Hi guys

I’m trying to write a public method that called isValidLength(String s) that returns true if s is the correct length of 6, and otherwise returns false if <6 or >6

Here is what i have so far…What to I need to enter to make the above possible?

string


#2

No need to make a duplicate topic, its a forum, just patiently wait for a reply.

it seems you need a way to get the length:

https://www.tutorialspoint.com/java/java_string_length.htm

furthermore, a if statement to see if the length equals 6, and a else in case the length isn’t 6.


#3

I’ve had a look at a few tutorials like this and gets where they’re coming from. However I’m struggling to link this together with true or false.

I know that it needs to be along the lines of…

If isValidLength(String s) == 6
then True
Else False

But i just don’t know how to put this into Java code


#4

where does then come from all of a sudden, look here:

https://www.tutorialspoint.com/java/if_else_statement_in_java.htm

how we can use if/else


#5

Thanks, I’ll give this a try


#6

Are you still stuck?

If so what exactly is the problem, making the if/else statement or finding out the length of s?


#7

A bit of both to be honest with you. I know that the length of s should ==6 and nothing else. It’s just the implementation


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.