prateek9417
| Subject: question 1> isc specimen paper 2010 Fri Mar 12, 2010 8:49 pm | |
| Question 1 Design a program which inputs a date in six digit number format i.e. 141296 . Test the validity of the date and print the date in full form . If date is invalid then print a message as “ Invalid Date“ 1. Example : INPUT : 141296 OUTPUT : 14th December , 96 : VALID DATE 2. Example : INPUT : 230488 OUTPUT : 23rd April , 88 : VALID DATE 3. Example : INPUT : 300284 OUTPUT : INVALID DATE
import java.io.*; class Currency { private int th,hu,fhu,fi,te,f,on,amm; public Currency() { th=hu=fi=te=on=0; } public void input(int amm) { this.amm=amm; } public void print() { if(amm/1000>0) { th=amm/1000; System.out.println("1000 x "+th); amm=amm%1000; } if(amm/500>0) { fhu=amm/500; System.out.println("500 x "+fhu); amm=amm%500; } if(amm/100>0) { hu=amm/100; System.out.println("100 x "+hu); amm=amm%100; } if(amm/50>0) { fi=amm/50; System.out.println("50 x "+fi); amm=amm%50; } if(amm/10>0) { te=amm/10; System.out.println("10 x "+te); amm=amm%10; } if(amm/5>0) { f=amm/5; System.out.println("5 x "+f); amm=amm%5; } if(amm>0) { System.out.println("1 x "+amm); } } public String display(int num) { String s[]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"}; String t=""; while(num>0) { int n=num%10; t=s[n]+" "+t; num/=10; } return t; } } |
|
RC Active member
| Subject: Re: question 1> isc specimen paper 2010 Sat Mar 13, 2010 11:55 am | |
| import java.io.*; class S1001 { void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Pls give the 6 digit input : "); String str=br.readLine(); String months[]={"January","February","March","April","May","June","July","August","September","October","November","December"}; int d[]={31,28,31,30,31,30,31,31,30,31,30,31}; //String dd,m,y; int dd,m,y; dd=Integer.parseInt(str.substring(0,2)); m=Integer.parseInt(str.substring(2,4)); y=Integer.parseInt(str.substring(4,6)); if(y%4==0) d[1]=29; if(dd>d[m-1]) { System.out.println("Invalid Date"); return; } System.out.print(dd); if(dd%10==1) System.out.print("st"); else if(dd%10==2) System.out.print("nd"); else if(dd%10==3) System.out.print("rd"); else System.out.print("th"); System.out.print(" "+months[m-1]+","+y); } } |
|