Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class MyInner
location: class myouter2.MyOuter2
at myouter2.MyOuter2.main(MyOuter2.java:34)
Java Result: 1
It is NOT required that if two objects are unequal according to the
equals(java.lang.Object) method, then calling the hashCode() method
on each of the two objects must produce distinct integer results. However,
the programmer should be aware that producing distinct integer results for
unequal objects may improve the performance of hashtables.
so it will almost always return a different hashcode for distinct (ie, "!=", as opposed to "not 'equal'") objects.
It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results.
To honor the above contract we should always override hashCode() method whenever we override equals() method. If not, what will happen? If we use hashtables in our application, it will not behave as expected. As the hashCode is used in determining the equality of values stored, it will not return the right corresponding value for a key.
Matched expression found by findInLine: 34
ef56
The java.util.Scanner.nextLine() method advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end.
I think the source of confusion and main reason why this question has been asked so many times since 2005 is that in java, nothing exists after the last char in a string (i.e. charAt(6) doesn't exist); however, in regex (which java implements via a standard library), a zero-length character does exist after the last char in a string. Maybe the SCJP FAQ article doesn't make this fact very clear.
public class Regextest {
public static void main(String a[]){
String stream = "ab34ef";
Pattern pattern = Pattern.compile("\\d*");
//HERE * IS GREEDY QUANTIFIER THAT LOOKS FOR ZERO TO MANY COMBINATION THAT
//START WITH NUMBER
Matcher matcher = pattern.matcher(stream);
while(matcher.find()){
System.out.print(matcher.start());
}
}
012456
Ulf Dittmer wrote:
abalfazl hossein wrote:index starts from zero, and we have six characters.not 7
To put it another way, you have not read the article I pointed you to twice, why not?. You've been visiting this site for years, and have posted hundreds of times, but still you expect other people to do your work for you, when you could learn much faster by simply reading up on stuff - which people even take the time to point you to. I simply don't get that attitude.
indexOf(a) = 0
indexOf(b) = 1
indexOf(f) = 5
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6
at java.lang.String.charAt(String.java:686)
at regextest.Regextest.main(Regextest.java:26)
Java Result: 1
012456
Campbell Ritchie wrote:And what on earth is that code supposed to do? Did you really find it in the SCJP book? The sort of things you read in some books
![]()
It might help you pass the exam, but I think code like that in real life would lose you your job