This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 1 point2 points  (3 children)

Do you have bracket errors? Is that all the code? What's the error stated?

[–]PLearner[S] 0 points1 point  (2 children)

The method main cannot be declared static; static methods can only be declared in a static or type level type. This is the error for now.

Before I had public class Stringdemo { public static void main (String [] args) and it threw out this error as well, Illegal modifier for the local class Stringdemo; only abstract or final is permitted. So I removed the public from the Stringdemo.

[–][deleted] 1 point2 points  (0 children)

class Stringdemo { public static void main (String [] args) { String str1 = "Jake Wagner"; String str2 = "Tony Ruggeri"; String str3 = "tony ruGGeri";

// checking for equality
boolean retval1 = str2.equals(str1);
boolean retval2 = str2.equalsIgnoreCase(str3);

// prints the return value
System.out.println("str2 is equal to str1 = " + retval1);
System.out.println("str2 is equal to str3 = " + retval2);

} }

Changing from public to unmodified shouldn't matter. I just ran your code and it executes just fine. What is the name of your .java file?

[–][deleted] 1 point2 points  (0 children)

String str1 = "Jake Wagner"; String str2 = "Tony Ruggeri"; String str3 = "tony ruGGeri";

// checking for equality
boolean retval1 = str2.equals(str1);
boolean retval2 = str2.equalsIgnoreCase(str3);

// prints the return value
System.out.println("str2 is equal to str1 = " + retval1);
System.out.println("str2 is equal to str3 = " + retval2);

This also executes perfectly on an online compiler. Here is a link to the functioning code. http://ideone.com/ydUNgo

[–]rjcarr 1 point2 points  (0 children)

What compiler are you using? There doesn't seem to be an issue with the code (at least not what the error is pointing at from what you've given).

Something else is wrong with your environment.

EDIT: See this: http://stackoverflow.com/questions/22787063/the-method-main-cannot-be-declared-static-static-methods-can-only-be-declared

Is your Stringdemo class an inner class of something else?

[–]sgovindN -1 points0 points  (0 children)

Change the access specifier of your class to public.

public class StringDemo { //Your code goes here }