this site is to help students to learn coding in java platform and qbasic platform. all programs are ICSE and ISC level. Java programs java python Python programs
Date month and year program isc
import java.io.*; class Date_DDMMYY { public static void main(String args[]) throws IOException { BufferedReader br= new BufferedReader( new InputStreamReader(System.in)); int l, y, d, m; String dd, mm, yy; //array storing the maximum days of every month int maxdays[]={ 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 }; //array storing the month names String month[]={ "" , "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" }; System.out.print( "Enter any date in 8 digits (ddmmyyyy) format: " ); String date = br.readLine(); //inputting the date in String format l = date.length(); //finding number of digits in the given input if (l== 8 ) //performing the task only when number of digits is 8 { dd = date.substring( 0 , 2 ); //extracting the day in String format mm = date.substring( 2 , 4 ); //extracting the month in String format yy = date.substring( 4 ); //extracting the year in String format d = Integer.parseInt(dd); //day in Integer format m = Integer.parseInt(mm); //month in Integer format y = Integer.parseInt(yy); //year in Integer format if ((y% 400 == 0 ) || ((y% 100 != 0 )&&(y% 4 == 0 ))) // condition for leap year { maxdays[ 2 ]= 29 ; } /* checking whether the day, month and year are within acceptable range i.e. there cannot be an input like 35012013 because 35/01/2013 is unacceptable*/ if (m< 0 || m> 12 || d< 0 || d>maxdays[m] || y< 0 || y> 9999 ) // Performing Date Validation { System.out.println( "The day, month or year are outside acceptable limit" ); } else { /* First Part */ System.out.println( "Date in dd/mm/yyyy format = " +dd+ "/" +mm+ "/" +yy); /* Second Part */ System.out.print( "Date in dd, month name, yyyy format = " +dd+ " " +month[m]+ ", " +yy); } } else System.out.println( "Wrong Input" ); } } |
Output:
1) Enter any date in 8 digits (ddmmyyyy) format: 02052013
Date in dd/mm/yyyy format = 02/05/2013
Date in dd, month name, yyyy format = 02 May, 2013
Date in dd/mm/yyyy format = 02/05/2013
Date in dd, month name, yyyy format = 02 May, 2013
2) Enter any date in 8 digits (ddmmyyyy) format: 12111963
Date in dd/mm/yyyy format = 12/11/1963
Date in dd, month name, yyyy format = 12 November, 1963
Date in dd/mm/yyyy format = 12/11/1963
Date in dd, month name, yyyy format = 12 November, 1963
3) Enter any date in 8 digits (ddmmyyyy) format: 252013
Wrong Input
Wrong Input
4) Enter any date in 8 digits (ddmmyyyy) format: 29022013
The day, month or year are outside acceptable limit
The day, month or year are outside acceptable limit
Subscribe to:
Posts (Atom)
Second largest number in java using ternary operator
//Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...
-
import java.util.*; class riwi { public static void main(String[]args) { Scanner sc=new Scanner(System.in); System...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
-
import java.io.*; class snowball { public static void main()throws IOException { BufferedReader br = new BufferedReader(new InputStreamRead...