J
Jack Dowson
Hello Everyone:
I'm new to java.I'm now confused by the output of the following two
examples:
The first example:
import java.util.*;
class UtilCalender{
public static void main(String[] args){
Calendar c = Calendar.getInstance();
System.out.println("current date: ");
System.out.println("Year: " +c.get(c.YEAR));
System.out.println("Month: " + (c.get(c.MONTH)+1));
System.out.println("Day: " + c.get(c.DAY_OF_MONTH));
}
}
And the result is:
current date:
Year: 2007
Month: 5
Day: 1
The second example:
import java.util.*;
class UtilCalender1{
public static void main(String[] args){
Calendar c = Calendar.getInstance();
System.out.println("current date: ");
System.out.println(c.get(c.YEAR) + (c.get(c.MONTH)+1)
+c.get(c.DAY_OF_MONTH));
}
}
And the result is:
current date:
2013
What leads to the different output?
It can be easily interpreted in perl as different scalar context.Then
what's the reason in java?
Any reply will greatly be appreciated!
I'm new to java.I'm now confused by the output of the following two
examples:
The first example:
import java.util.*;
class UtilCalender{
public static void main(String[] args){
Calendar c = Calendar.getInstance();
System.out.println("current date: ");
System.out.println("Year: " +c.get(c.YEAR));
System.out.println("Month: " + (c.get(c.MONTH)+1));
System.out.println("Day: " + c.get(c.DAY_OF_MONTH));
}
}
And the result is:
current date:
Year: 2007
Month: 5
Day: 1
The second example:
import java.util.*;
class UtilCalender1{
public static void main(String[] args){
Calendar c = Calendar.getInstance();
System.out.println("current date: ");
System.out.println(c.get(c.YEAR) + (c.get(c.MONTH)+1)
+c.get(c.DAY_OF_MONTH));
}
}
And the result is:
current date:
2013
What leads to the different output?
It can be easily interpreted in perl as different scalar context.Then
what's the reason in java?
Any reply will greatly be appreciated!