currLet = str.charAt(currPos);
AString
value can’t be assigned to achar
, they are different types, apples and orangesif (currLet = str.charAt(currPos + 1)) {
is actually an assignment (makecurrLet
equal to the value ofstr.charAt(currPos + 1)
)if (currLen > maxLen) {
–maxLen
is undefined- You never
return
anything from the method…
Try changing:
String currLet = "";
to something more likechar currLet = '\0';
andString maxLet = "";
tochar maxLet = '\0';
if (currLet = str.charAt(currPos + 1)) {
to something likeif (currLet == str.charAt(currPos + 1)) {
- Add
int maxLen = 0
to your variable declerations (may be underint maxCount = 0
)
Now, based on your example code, public int longestRep(String str) {
will need to be public static int longestRep(String str) {
in order for you to call from you main
method…
Related Posts:
- Java compile error: “reached end of file while parsing }”
- Non-static variable cannot be referenced from a static context
- Non-static variable cannot be referenced from a static context
- Non-static variable cannot be referenced from a static context
- Else without if
- Error: Could not find or load main class in intelliJ IDE
- What does “error: ‘.class’ expected” mean and how do I fix it
- Java error: void cannot be converted to String
- Fatal error compiling: tools.jar not found:
- Error: ‘)’ expected compiler error
- java attempting to assign weaker access privilege error
- What is the difference between run-time error and compiler error?
- intellij idea – Error: java: invalid source release 1.9
- String index out of bounds exception java
- What exactly is Apache Camel?
- What is an instance variable in Java?
- How does the Java ‘for each’ loop work?
- How does the Java ‘for each’ loop work?
- What does “Could not find or load main class” mean?
- How do I create a file and write to it?
- When to use LinkedList over ArrayList in Java?
- How to convert a char to a String?
- How do you create a dictionary in Java? [closed]
- How do I declare and initialize an array in Java?
- Convert list to array in Java [duplicate]
- How do I generate random integers within a specific range in Java?
- “Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0″ with ArrayList?
- Raising a number to a power in Java
- Running JAR file on Windows 10
- java.io.FileNotFoundException: the system cannot find the file specified
- How to parse this string in Java?
- How to match “any character” in regular expression?
- Double array initialization in Java
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- “Symbol(s) not found for architecture x86_64” on QtCreator project
- I want to declare an empty array in java and then I want do update it but the code is not working
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- Java Security: Illegal key size or default parameters?
- Could not reserve enough space for object heap
- Eclipse: Java was started but returned error code=13
- Why java unknown: import org.apache.commons.codec.binary.Base64;?
- Extracting .jar file with command line
- Unable to create requested service [org.hibernate .engine.jdbc.env.spi.JdbcEnvironment]-MySQL
- Why do I get “Exception; must be caught or declared to be thrown” when I try to compile my Java code?
- Check jdk/JRE is installed and get path for jvm.dll
- What is Java String interning?
- Good Java graph algorithm library?
- Integrate Ant builder into Eclipse: Error “Variable references empty selection”
- Spring Maven clean error – The requested profile “pom.xml” could not be activated because it does not exist
- Java Class File Editor
- Error Importing SSL certificate : Not an X.509 Certificate
- How do I draw a triangle?
- warning: [options] bootstrap class path not set in conjunction with -source 1.5
- Class ‘Room’ is abstract; cannot be instantiated
- Creating a maze solving algorithm in Java
- IDEA: javac: source release 1.7 requires target release 1.7
- Can we write our own iterator in Java?
- local variables referenced from a lambda expression must be final or effectively final
- java.lang.IllegalMonitorStateException: object not locked by thread before wait()?
- WebServlet cannot be resolved to a type
- How do I print out the value of this boolean? (Java)
- How to add an object to an ArrayList in Java
- Picked up _JAVA_OPTIONS: -Xmx256M
- When to use static methods
- How to serialize an object into a string
- Getting the array length of a 2D array in Java
- Java String to SHA1
- How do I call one constructor from another in Java?
- Does Java have something like C#’s ref and out keywords?
- How to upload a file and JSON data in Postman?
- What is the difference between i++ & ++i in a for loop?
- when to throw FileNotFoundException
- How to use ArrayUtils for array of objects, it doesn’t delete the content of an array
- The ResourceConfig instance does not contain any root resource classes
- Which exception to throw for invalid input which is valid from client perspective
- Error: Could not find or load main class net.minecraft.launchwrapper.Launch when launching Minecraft 1.12.2 with Forge
- IllegalArgumentException: Bound must be positive
- Eclipse is executing the wrong Java file
- Understanding BufferedImage.getRGB output values
- What is the purpose of creating static object in Java?
- How to print a method in java
- build-impl.xml:1031: The module has not been deployed
- Spring-Security-Oauth2: Full authentication is required to access this resource
- Why is System.out.print() not working?
- setMnemonic() and call a method by pressing the key
- What is `AnyType` in java generics
- “insufficient memory for the Java Runtime Environment ” message in eclipse
- How to ping an IP address
- Android: how to create Switch case from this?
- Read next word in java
- Convert float to double without losing precision
- Exception in thread “AWT-EventQueue-0” java.lang.OutOfMemoryError: Java heap space
- How do the post increment (i++) and pre increment (++i) operators work in Java?
- Manually throw an exception
- Spring boot: Unable to start embedded Tomcat servlet container
- How does paintComponent work?
- toring and Retrieving ArrayList values from hashmap
- Could not find or load main class with a Jar File
- “uses unchecked or unsafe operations” [duplicate]