M
M
Makaron30002021-05-24 15:36:30
Java
Makaron3000, 2021-05-24 15:36:30

Why swears at length?

When executing the code, it gives an error - /src/main/java/Kata.java:3: error: cannot find symbol
for(int i = 0; i < haystack.length(); i++){
^
symbol: method lenght()
location : variable haystack of type Object[]

Code:

public class Kata {
  public static String findNeedle(Object[] haystack) {
    for(int i = 0; i < haystack.length(); i++){
      if(haystack[i] == "needle"){
        return "found the needle at position " + i;
      }
    }
    return "Makaron3000";
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2021-05-24
@Makaron3000

haystack.lenght - no brackets

J
Jacen11, 2021-05-25
@Jacen11

parentheses are put when it is a method and it can accept something, or not (but theoretically it can), and the field, by definition, cannot accept any parameters, therefore they do not have brackets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question