Please help me to solve this java code....:-) find the errors in this code shown in the following comment.....
import java.util.Calendar; public class Calendar1{{ public static void main(String []args){ Calendar now = Calendar.getInstance(); System.out.println("Current date :" + (now.get(Calendar.MONTH)+1)+"-"+(now.get(Calendar.DATE))+"-"+(now.get(Calendar.YEAR))); now.add(Calendar.DATE,1); System.out.println("Date after one day :" + (now.get(Calendar.MONTH)+1)+"-"+(now.get(Calendar.DATE))+"-"+(now.get(Calendar.YEAR))); now = Calendar.getInstance(); now.add(Calendar.DATE, -10); System.out.println("Date after one day :" + (now.get(Calendar.MONTH)+1)+"-"+(now.get(Calendar.DATE))+"-"+(now.get(Calendar.YEAR))); } }
What is the output of the program?
output is: current date in our system Date after one day i.e., tomorrows date Date before ten days ......@jtryon
import java.util.Calendar; public class Calendar1{ public static void main(String []args){ Calendar now = Calendar.getInstance(); System.out.println("Current date :" + (now.get(Calendar.MONTH)+1)+"-"+(now.get(Calendar.DATE))+"-"+(now.get(Calendar.YEAR))); now.add(Calendar.DATE,1); System.out.println("Date after one day :" + (now.get(Calendar.MONTH)+1)+"-"+(now.get(Calendar.DATE))+"-"+(now.get(Calendar.YEAR))); now = Calendar.getInstance(); now.add(Calendar.DATE, -10); System.out.println("Date before ten days :" + (now.get(Calendar.MONTH)+1)+"-"+(now.get(Calendar.DATE))+"-"+(now.get(Calendar.YEAR))); } } Fixed the code, you had an extra bracket before the start of the main class, removed that and it compiles fine and outputs, also fixed the last text of the third string. Cheers! :)
Thank you.... @Oinea
Join our real-time social learning platform and learn together with your friends!