Vicky Mehta

Greenhorn
+ Follow
since Jul 15, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vicky Mehta

If the ',' ('\u002c') flag is given, then the locale-specific grouping separator is inserted by scanning the integer part of the string from least significant to most significant digits and inserting a separator at intervals defined by the locale's grouping size.


http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax
, indicates that the digits in the number should use the default digit seperator of the system locale. It is well possible that the system locale of you computer is set to such locale in which the digit seperator is a space. hence, your display is like like that.
There are two options to change that:
1) Change default system locale in the system in Control Panel -> Regional and Language Options to such a locale in which the seperator is a comma. Remember to reinvoke the command prompt and then execute your program.
2) Invoke following printf
http://download.oracle.com/javase/6/docs/api/java/io/PrintStream.html#printf(java.util.Locale,%20java.lang.String,%20java.lang.Object...)
instead of
http://download.oracle.com/javase/6/docs/api/java/io/PrintStream.html#printf(java.lang.String,%20java.lang.Object...)
for the first parameter you can Locale as LOCALE.US for which AFAIK the seperator is a comma.
Minor correction in output

int i1 = -123; System.out.printf(">%1$(7d< \n", i1);


will be
Note 2 leading spaces before open braces
A parallel scenario is also described and highlighted in Exam Watch Page 500 of K & B.

Zero-length matches can occur in several places:
a) After the last character of source data....

Thanks Valentin.
The compiler seems to contradict and am not able to understand the reason for the same. It would be be nice if anyone can provide an explanation for this question.
@Sahil:
Have you been able to reason out the behavior of the compiler for this question.
Compiler behavior:
1) Compilation Error with ambiguous method.
2) Compilation Successful

My reasoning:
Both MyInterface and java.io.Serializable being Marker interfaces(interfaces with no methods), why is the compiler differentiating between the two interfaces implemented by the class.
I copy-pasted the code and have been able to compile and execute it without any errors and output being
alpha subsub
Is it anything to do with the compiler version or?....

Sandra Bachan wrote:Modification to Sierra/Bates, Chapter 3, Question 7.

Please note line 14 where Suits.SPADES automatically prints the name of the enum.

Question 1: Is this an in-built function of the enum?

Question 2: How do I implement toString() such that is prints the name of the Suits object in all lower-case. I attempted this in line 9, but in vain.


AFAIK
1) Suits.SPADES is an Enum Constant.
An Enum constant is internally a a final static reference of the Enum Type Suits.
When Suits.SPADES is referred to in the function System.out.println, toString() function of this reference will be invoked.
Default toString() function of the Enum class invokes the name() function of the Enum class which returns the constant name as declared in the enum.

2) Replacing toString() function in this code to the code below would give you the desired result:
public String toString(){ return name().toLowerCase();}
This invokes the same name() function as mentioned above followed by toLowerCase() function of the String class.
Cud someone provide an answer to this query? and reason for that behavior?

the output would be BA?


ouptut is AB

but when pq.poll() method is called (with pq containing a string of char with String type safe) its supposed to remove the highest priority element in that priority queue isn'it?
will always give unordered output.
But in palce of one two, had I placed 1, 2,80,3,7 then the output is ordered just like how a ideal priorotyqueue as to work


No, output for pq containing a string of char with String type will be as per the natural ordering of strings which is lexicographical ordering(that is their comparison will be based on Unicode value of each character in the strings). Hence, out for the program will be :

Note ' '(space) character before the string eighty