Java provides the Date class to find the the current date and time,generally this Date class encapsulates the Date and current Time .we can use this with toString to and get the current date and time.Here is an example:
import java.util.Date; //import Date from the util package
public class DateDemo
{
public static void main(String args[])
{
Date date=new Date(); //date object of Date class
System.out.print(date.toString());
}
}
O/P:Sat Nov 08 13:01:31 IST 2014
WAP to wish Happy New Year
This program was developed to wish the happy new to your friends.In this program we used the buffered Reader to take the input from user,Assumed the current year is 2014 and December end,so if we give a input 2014 it will say that Say goodbye to 2014,if we put 2015 then it will show that Wish you happy new year 2015.but if we don't put 2014 or 2015 then it will show that please enter correct input.lets try it.import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class HappyNewYear
{
int year;
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the year:");
int year=Integer.parseInt(br.readLine());
if(year==2014)
System.out.println("SAY GOODBYE TO 2014");
else if(year==2015)
System.out.println("\"WISH YOU HAPPY NEW YEAR 2015\"");
else System.out.println("pK ho kya????Pls enter correct input!!");
}
}
O/P:
Enter the year:2014
SAY GOODBYE TO 2014
Enter the year:2015
"WISH YOU HAPPY NEW YEAR 2015"
Enter the year:2010
pK ho kya????Pls enter correct input!!
No comments:
Post a Comment