Proj 3 Miscellaneous

Embed Size (px)

DESCRIPTION

proj

Citation preview

ICSE PROJECT - 3MISCELLANEOUS PROGRAMS

NAME: MADHURIMA DATTA

CLASS - X SECTION - B

ROLL NO - 12

SCHOOL: A.G. CHURCH ASANSOL

program - 2

PROGRAM 2:

WAP to print the factorial of a number n using the concept of Recursive function.

VARIABLE LISTING

Serial noVariable nameVariable typeVariable description

1facintfactorial calculator

2nintnumber

PROGRAM

class factorial

{ int fac=1;

int perform(int n)

{if(n>0)

{ fac=fac*n;

perform(n-1); }

return fac;

}

}

program - 5

PROGRAM 5:

Enter the name of a month and the day on which the first day of the month starts . Print the calendar of the month in the given format .

For example::

SUN MON TUE WED THRUS FRI SAT

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

VARIABLE LISTING

Serial noVariable nameVariable typeVariable description

1mStringmonth name

2mnStringday

3iintloop variable

4kintcounter variable

5ndintmonth counter

6spintday counter

7yrintyear variable

PROGRAM

import java.io.*;

class calender

{String m,mn;int i,k,nd,sp=0,yr;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

void print()throws IOException

{

System.out.println("enter name of the month");

m=br.readLine();

m=m.trim();

m=m.toLowerCase();

if(m.equals("january")||m.equals("march")||m.equals("may")||m.equals("july")||m.equals("august")||m.equals("october")||m.equals("december"))

nd=31;

if(m.equals("april")||m.equals("september")||m.equals("november"))

nd=30;

if(m.equals("february"))

{ System.out.println("Enter the year");

yr=Integer.parseInt(br.readLine());

if(yr%100==0)

{if(yr%400==0)

nd=29;

else

nd=28;

}

if(yr%4==0)

nd=29; else

nd=28;

}

System.out.println(":Enter first day falls on");

mn=br.readLine();

mn=mn.toLowerCase();

if(mn.equals("monday"))

sp=1;

if(mn.equals("tuesday"))

sp=2;

if(mn.equals("wednesday"))

sp=3;

if(mn.equals("thursday"))

sp=4;

if(mn.equals("friday"))

sp=5;

if(mn.equals("saturday"))

sp=6;

if(mn.equals("sunday"))

sp=0;

System.out.println(" SUN \tMON \tTUES \tWED \tTHURS \tFRI \tSAT");

for(i=0;i