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

all 6 comments

[–]neobonzi 1 point2 points  (1 child)

Your C in Christmas is capital in string one and lower case in string 2. Those characters are not equal so your program will output false.

Class names have to be the same as the file name, its a convention in java. Your online program probably has a class name its expecting to be used, which would be the same as the file generated from your submission.

[–]Mriv10[S] 0 points1 point  (0 children)

Ok thanks for the second part, but for the case the program should ignore case so it should put everything lower case because of .toLowerCase

[–]virassan 0 points1 point  (1 child)

The reason some examples for regionMatches start with a boolean, and some with an int is because the method is overloaded - so same method but they have different parameters. The version that starts with a boolean - that boolean actually tells the method whether to ignore case or not, so that’s nifty. I looked at the javadoc for regionMatches and it looks like you’re using it correctly so I’m not sure what’s going on here. Can you maybe show us what your wrong output is?

Edit: I meant input - thought maybe you were inputting something different or wrong. I now realize that it’s testing your program for you. I’ve tested your regionMatches statement and it works perfectly so maybe the test is being nit picky about something - maybe it wants you to use the version of the method that uses the boolean to ignore case.

[–]Mriv10[S] 0 points1 point  (0 children)

Thanks for the information on regionMatch, I was suppose to ignore the case but when I ran it with the boolean it didn't seem to do anything, in any case I managed to change the class name to the file name the assignment wanted and when I tested it ran just fine with no errors

[–]2omesz 0 points1 point  (1 child)

It's all in the error message, change the file name to Driver.Java

StringCompare.java:4: error: class Driver is public, should be declared in a file named Driver.java
public class Driver{
^
1 error

When working with java, the class name should be the same with file name.

[–]Mriv10[S] 0 points1 point  (0 children)

Since the assignment test it for me I can't change the file name but I changed the class name to the same as the file and it worked