Beruflich Dokumente
Kultur Dokumente
SL
TOPIC PAGE NO.
NO.
ANAGRAMS
27. 65-67
30. DISPLAY THE CALENDAR OF A MONTH BY ACCEPTING THE FIRST DAY OF THE 73-76
MONTH.
ALGORITHM
STEP 1: START
STEP 2: Accept value of n
STEP 3: for i=0 to n, repeat STEP 4
STEP 4: for j=0 to n, repeat STEP 5
STEP 5: read a[i,j]
STEP 6: for i=0 to n, repeat STEP 7
STEP 7: for j=0 to n-1, repeat STEP 8
STEP 8: for k=0 to n-j-1, repeat STEP 9
STEP 9: if (a[i][k]>a[i][k+1]) is true switch the numbers
STEP 10: for i=0 to n, repeat STEP 11
STEP 11: for j=0 to n, repeat STEP 12
STEP 12: Display c[i,j]
STEP 13: END
SOLUTION
import java.util.*;
class Arrange_matrix
{ static void main()
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of array");
int n= sc.nextInt();//accepting size of array
int a[][]=new int[n][n];//declaring array
System.out.println("Enter array elements");
for(int i=0;i<n;i++)//accepting array
for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
for(int i=0;i<n;i++)//sorting array
{ for(int j=0;j<n-1;j++)
{ for(int k=0;k<n-j-1;k++)
if(a[i][k]>a[i][k+1])
{ int temp=a[i][k];
a[i][k]=a[i][k+1];
a[i][k+1]=temp;
}}}
for(int i=0;i<n;i++)//displaying array
{ for(int j=0;j<n;j++)
System.out.print(a[i][j]+"\t");
System.out.println();
}}}
Output:
Output:
Output:
Algorithm
STEP 1: START
STEP 2: Accept value of n
STEP 3: for i=0 to n, repeat STEP 4
STEP 4: for j=0 to n, repeat STEP 5
STEP 5: read a[i,j]
STEP 6: for i=0 to n, repeat STEP 7
STEP 7: for j=0 to n-1, repeat STEP 8
STEP 8: for k=0 to n-j-1, repeat STEP 9
STEP 9: if (a[i][k]>a[i][k+1]) is true switch the numbers
STEP 10: for i=0 to n, repeat STEP 11
STEP 11: for j=0 to n, repeat STEP 12
STEP 12: Display c[i,j]
STEP 13: END
*****************
Program: To arrange elements of each row in ascending
order using bubble sort
Output:
*****************
Program: Magic number using recursion
Output:
Output:
Algorithm
main()
STEP 1: Accept number and store in variable a
STEP 2: Repeat STEP 3 until a>9
STEP 3: Calculate magic number
STEP 4: Check for magic number
STEP 5: If STEP 4 is true, display Magic number OTHERWISE display not a magic number
checknum(int n)
STEP 1: Receive actual parametric value in variable n
STEP 2: if (n=0) is true then return 0
STEP 3: Otherwise (int)Math.pow(n%10,3)+ checknum(n/10);
*****************
Output:
Algorithm
main()
STEP 1: Accept number
task(int n)
STEP 1: Proceed if n>2
STEP 2: store remainder in variable d when n is divided by 2
STEP 3: task(n/2)
STEP 4: Display d backwards in horizontal line
*****************
Output:
*****************
Output:
Algorithm
STEP 1:START
STEP 2: Create a FileReader stream type object
STEP 3: Link the FileReader object from STEP 1 with a BufferedReader object
STEP 4: Repeat STEP 5 and STEP 6 until readLine() is null
STEP 5: Read text using readLine() from this BufferedReader object and store in a string object
STEP 6: Display the string object
STEP 7: Close the stream chain by using close()
STEP 8: END
*****************
Output:
Output:
Output:
Algorithm
STEP 1: START
STEP 2: Find length of the entered word and store in variable l
STEP 3: for i=l-1 to 0, repeat STEP 4
STEP 4: w=w+s.charAt(i)
STEP 5: If s=w, then display Palindrome otherwise display not palindrome
STEP 6: END
*****************
Output:
Algorithm
STEP 1: START
STEP 2: Find length of the entered word and store in variable l
STEP 3: for i=0 to l-1, repeat STEP 4,5,6
STEP 4: Extract characters of the word and store in variable ch
STEP 5: if ch is a vowel, ch=ch+1
STEP 6: str= str+ch
STEP 7: Display the original word and the new word
STEP 8: END
*****************
Output:
*****************
Program: Delete Multiple Character from a Sentence
Output
Algorithm
STEP 1: Start
STEP 2: Separating date ,month and year from input
STEP 3: Checking for leap year
STEP 4: Checking for invalid date
STEP 5: Accepting day to calculate past date
STEP 6: Calculating past date
STEP 7: Displaying past date
STEP 8: End
import java.util.Scanner;
class pastDate
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
System.out.print("Enter the Submission Date in (dd/mm/yyyy) format: ");
String date=sc.nextLine().trim();
int p,q,count=0;
p=date.indexOf("/");
int d=Integer.parseInt(date.substring(0,p));//EXTRACTING DAYS
q=date.lastIndexOf("/");
int m=Integer.parseInt(date.substring(p+1,q));
int y=Integer.parseInt(date.substring(q+1));
System.out.println("Entered Project Submission Date: "+date);
if((y%400==0) || ((y%100!=0)&&(y%4==0)))//CHECKING LEAP YEAR
month[2]=29;
else
month[2]=28;
if(m<0 || m>12 || d<0 || d>month[m] || y<0 || y>9999)//VALIDATION OF DATE
{
System.out.println("Invalid Date");
}
else
{
System.out.print("Enter number of days alloted for the project: ");
int days=Integer.parseInt(sc.nextLine());
while(count<days)//LOOP TO FIND PAST DATE
{
d--;
count++;
if(d<1)
{
d=month[m-1];//STORING PREVIOUS MONTH NUMBER OF DAYS
m--;
}
if(m<1)
{
y--;
m=12;
d=month[m];
if((y%400==0) || ((y%100!=0)&&(y%4==0))) //CHECKING FOR LEAP YEAR
month[2]=29;
else
month[2]=28;
}
}
System.out.println("Date on which project was given: +d+"/"+m+"/"+y);
}
}
}
Output:
Algorithm
STEP 1: Start
STEP 2: void gettime(int nh,int nm)
Initialization of data members nh to hrs and nm to min
STEP 3: Time sumoftime(Time t1,Time t2)
We take two object in method sum of time as t1 and t2
Create a new object c and declare it min and hrs as sum of min of both the object
t1 and t2.
STEP 4: Return the created object
STEP 5: void display()
Display the hrs and min of the new created object
STEP 6: void main(int hr1,int min1,int hr 2,int min 2 )
Declare object ob1 and ob2
Call Function gettime(hr1,min1) by ob1 and gettime(hr2,min2) by ob2
Call display function using ob1 as well as ob2
Use ob3 object as variable to call function sumoftime(ob1,ob2)
Lastly call display function using ob3
STEP 7: End
import java.util.Scanner;
class Time
{
Scanner sc=new Scanner(System.in);
int hrs,min;
Time()
{
hrs=0;
min=0;
}
void display()
{
System.out.println(hrs+" hours"+" "+min+" minutes");
}
Output:
Algorithm
STEP 1: Start
STEP 2: void inputangle()
Initialization of data members deg and min
STEP 3: Angle sumofangle (Angle t1,Angle t2)
We take two object in method sum of angle as t1 and t2
Create a new object c and declare its deg & min and hrs as sum of deg&min of
both the object t1 and t2.
STEP 4: Return the created object
STEP 5: void display()
Display the deg and min of the new created object
STEP 6: void main()
Declare object ob1 and ob2
STEP 7: Call Function inputangle()by ob1 and inputangle()by ob2
Call display function using ob1 as well as ob2
Use ob3 object as variable to call function sumofangle(ob1,ob2)
Lastly call display function using ob3
STEP 8: End
import java.util.Scanner;
class Angle
{
Scanner sc=new Scanner(System.in);
int deg,min;
Angle()
{
deg=0;
min=0;
}
void inputangle()
{
System.out.println("enter degree");
deg=sc.nextInt();
System.out.println("enter minutes");
min=sc.nextInt();
}
Angle sumofangle(Angle t1,Angle t2)
{
Angle c=new Angle();
c.min=t1.min+t2.min;
c.deg=t1.deg+t2.deg;
c.deg=c.deg+(int)(c.min/60);
c.min=c.min%60;
return c;
}
void display()
{
System.out.println(deg+" degree"+" "+min+" minutes");
}
void main()
{
Angle ob1=new Angle();
Angle ob2=new Angle();
ob1.inputangle();
ob2.inputangle();
ob1.display();
ob2.display();
Angle ob3=sumofangle(ob1,ob2);
ob3.display();
}
}
Output:
Algorithm
STEP 1: Start
STEP 2: collection()
Initialization of data members len=0
STEP 3: collection(int a)
STEP 4: Initialization of data members len=a
And declare array of size a
STEP 5: void inparr()
to enter array elements
STEP 6: Collection common (Collection a)
We take object in method common as a
Create a new object b and declare and add the common elemnts of that array and
current array in the new array of the new object
Change the length of the new object accordingly
Return the created object
STEP 7: void arrange()
To sort the common elements in assending order using bubble sort
STEP 8: void display()
Display the sorted array
STEP 9: void main(int l1,int l2)
Declare object ob1 of length l1 and ob2 of length l2 respectively.
STEP 10: Call Function inparr()by ob1 and inparr()by ob2
Use ob3 object as variable to call function common(ob1) using ob2
Lastly call display function using ob3
STEP 11: End
import java.util.Scanner;
class collection
Scanner sc=new Scanner(System.in);
int arr[],len;
collection()
{
len=0; }
collection(int a)
{ arr=new int[a];
len=a;
for(int i=0;i<len;i++)
{ arr[i]=0;
} }
void inparr()
{ for(int i=0;i<len;i++)
{ System.out.println("enter");
arr[i]=sc.nextInt(); }
}
collection common(collection a)
{ collection b=new collection(len);
int k=0;
for(int i=0;i<len;i++)
{ for(int j=0;j<a.len;j++)
{ if(arr[i]==a.arr[j])
{ b.arr[k++]=arr[i];
break; }
} }
b.len=k;
return b; }
void arrange()
{ for(int i=0;i<len-1;i++)
{ for(int j=0; j<len-i-1; j++)
{ if(arr[j] > arr[j+1])
{ int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
} } } }
void display()
{
for(int i=0;i<len;i++)
{
System.out.print(arr[i]+" ");
} }
void main(int l1,int l2)
{
collection ob1=new collection(l1);
collection ob2=new collection(l2);
ob1.inparr();
ob2.inparr();
collection ob3=ob2.common(ob1);
ob3.arrange();
ob3.display();
}}
Output:
Algorithm
STEP 1: Start
STEP 2: Take a and b as parameterized input
STEP 3: Declare I,j,c,and d
STEP 4: Run loop i to a and add all factor in c
STEP 5: Run loop j to b and add all factor in d
STEP 6: Check if c is equal to b and d is equal to a
STEP 7: If true then amecable else not
STEP 8: End
Output:
A Circular Prime is a prime number that remains prime under cyclic shifts of its digits.
When the leftmost digit is removed and replaced at the end of the remaining string of
digits, the generated number is still prime. The process is repeated until the original
number is reached again.
A number is said to be prime if it has only two factors I and itself.
Example:
131
311
113
Hence, 131 is a circular prime.
Algorithm
STEP 1: Start
STEP 2: Take a and b as parameterized input
STEP 3: Declare I,j,c,and d
STEP 4: Run loop i to a and add all factor in c
STEP 5: Run loop j to b and add all factor in d
STEP 6: Check if c is equal to b and d is equal to a
STEP 7: If true then amecable else not
STEP 8: End
int circulate(int n)
{
String s = Integer.toString(n);
String p = s.substring(1)+s.charAt(0);
int a = Integer.parseInt(p);
return a;
}
void isCircularPrime(int n)
{
int f = 0,a = n;
do
{
System.out.println(a);
if(isPrime(a)==false)
{
f = 1;
}
a = circulate(a);
}while(a!=n);
if(f==1)
System.out.println(n+" IS NOT A CIRCULAR PRIME");
else
System.out.println(n+" IS A CIRCULAR PRIME");
}
Output:
A super class Detail has been defined to store the details of a customer. Define a subclass Bill to
compute the monthly telephone charge of the customer as per the chart given below:
Number Of Calls Rate
1 – 100 Only Rental charge
101 – 200 60 paisa per call + rental charge
201 – 300 80 paisa per call + rental charge
Above 300 1 rupee per call + rental charge
Algorithm
SUPER CLASS
STEP 1: Start
STEP 2: Accept personal details
STEP 3: Print them in display
STEP 4: End
BASE CLASS
STEP 1: Start
STEP 2: Assign value to super class variable using super keyword
STEP 3: Calculating amount to be paid as per number of calls
STEP 4: Printing details
STEP 5: End
void show()
{
System.out.println("Name of customer = "+name);
System.out.println("Address = "+address);
System.out.println("Telephone Number = "+telno);
System.out.println("Monthly Rental = Rs. "+rent);
}
} //end of superclass Detail
class Bill extends Detail //subclass
{ int n;
double amt;
Output:
Specify the class Point, giving details of the constructor and void display(). Using the
concept of inheritance. specify a class Circle giving details of the constructor, void
calDistance() and void display().Do not write main() function.
Algorithm
SUPER CLASS
STEP 1: Start
STEP 2: Parameterized constructor to initialize the point coordinates
STEP 3: Displaying the points
STEP 4: End
BASE CLASS
STEP 1: Start
STEP 2: Parameterized constructor to initialize the variables by invoking the constructor of
the parent class
STEP 3: CalDistance function to calculate the distance between two points and storing in r
STEP 4: Calling the display func of parent class and displaying the radius
STEP 5: End
class Point
{
int x1,x2,y1,y2;
Point(int a,int b,int c,int d)
{
x1=a;
x2=b;
y1=c;
y2=d;
}
void display()
{
System.out.println("The coordinates are - ("+x1+","+y1+") and
("+x2+","+y2+")");
}
}
public class circle extends Point
{
double r;
circle(int a,int b,int c,int d)
{
super(a,b,c,d);
r=0.0;
}
public void calDistance()
{
r=Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
}
void display()
{
super.display();
System.out.println("The length of the radius = "+r+" units");
}}
Output:
Algorithm
STEP 1 : START
STEP 2 : [Create the first list of the structure]
Accept(start->temp)
start->link=NULL
STEP 3 : [Initialize the temporary objects]
ptr=start
STEP 4 : [Input number of nodes to be created]
Accept(“Numbers of nodes-”,n)
count=0
STEP 5 : [Create other nodes of the linked list structure and connect them]
Repeat through steps 6 and 7 while(c<n)
STEP 6 : [Create a temporary node]
Accept(temp->data)
temp->link=NULL
STEP 7 : [Connect the temporary list in existing linked list]
ptr->link=temp
ptr=ptr->link
c=c+1
temp=NULL
ar[rear]=n
STEP 8 : [Withdraw temporary pointer ptr]
ptr=NULL
STEP 9 : [Create a single list]
Accept(temp->data)
STEP 10 : [Initialize ptr object to refer first list]
ptr=start
STEP 11 : [Locate the last link of the linked list structure]
while(ptr->link!=NULL)
ptr=ptr->link
endwhile
STEP 13 : [Insert the list]
ptr->link=temp
STEP 14 : END
import java.util.*;
class node
{ int data;
node link;
void create()//creating a linked list
{ Scanner OB= new Scanner(System.in);
System.out.println("Enter the first data-");
this.data= OB.nextInt();
System.out.println("Enter number of nodes to be
created-");
int n=OB.nextInt();
node temp;
node ptr=this;
for(int i=1; i<n;i++)
{ temp= new node();
System.out.println("Enter next data");
temp.data= OB.nextInt();
temp.link= null;
ptr.link= temp;
temp=null;
ptr=ptr.link; }}
void insertend(node start, int x)//inserting a list
{ node temp= new node();
temp.data=x;
node ptr=start;
while(ptr.link!=null)
{ ptr=ptr.link; }
ptr.link=temp; }
void display()//displaying the elements
{ System.out.println("Linked list-");
node ptr=this;
while(ptr!=null)
{ System.out.println(ptr.data);
ptr=ptr.link; }}
static void main()
{ Scanner OB = new Scanner(System.in);
System.out.println("Enter the no. to be inserted");
int k = OB.nextInt();
node first = new node();
first.create();
first.insertend(first,k);
first.display(); }}//end of class
3 i int Counter
Output:
Algorithm
STEP 1 : START
STEP 2 : [Create the first list of the structure]
Accept(start->temp)
start->link=NULL
STEP 3 : [Initialize the temporary objects]
ptr=start
STEP 4 : [Input number of nodes to be created]
Accept(“Numbers of nodes-”,n)
count=0
STEP 5 : [Create other nodes of the linked list structure and connect them]
Repeat through steps 6 and 7 while(c<n)
STEP 6 : [Create a temporary node]
Accept(temp->data)
temp->link=NULL
STEP 7 : [Connect the temporary list in existing linked list]
ptr->link=temp
ptr=ptr->link
c=c+1
temp=NULL
ar[rear]=n
STEP 8 : [Withdraw temporary pointer ptr]
ptr=NULL
STEP 9 : [Initialize Ptr and ptr1 objects referring Start]
Ptr=Start
Ptr1=Start
STEP 10 : [Initialize the counter]
Count=0
STEP 11 : [Locate nth node to be deleted]
Repeat while (Count<n)
Ptr1=Ptr
Ptr=Ptr->link
Count=Count+1
Endwhile
STEP 12 : [Delete the list]
Ptr1->link=Ptr->link
Ptr->link=NULL
STEP 13 : [Withdraw the temporary pointers]
Ptr=NULL
Ptr1=NULL
STEP 14 : return
STEP 15 : END
import java.util.*;
class nodal
{ int data;
nodal link;
public nodal()
{
data=0;
link=null; }
public static void main()
{
Scanner sc= new Scanner(System.in);
nodal ob=new nodal();
int ch,n,k,e,s=1;
do {
System.out.println("Enter 1 to create List");
System.out.println("Enter 2 to delete element");
System.out.println("Enter 3 to to display List");
System.out.println("Enter your choice");
ch=sc.nextInt();
switch(ch)
{
case 1:ob.create();
break;
case 2:System.out.println("Enter the node number you want to delete");
n=sc.nextInt();
ob.delete(ob,n);
break;
case 3:ob.display();
break;
default : System.out.println("Wrong choice");
}
System.out.println("Do you want to continue?(1/0)");
s=sc.nextInt();
}
while(s!=0);
}
}//end of class
3 i int Counter
7 s int checker
Output:
Algorithm
STEP 1 : START
STEP 2 : Define array a
STEP 3 : Accept row and coloumn from user and check if square matrix or not
STEP 4 : Repeat i from 0 to n an j from 0 to n and take input in array
STEP 5 : Repeat i from 0 to n an j from 0 to n and display the inputted array
STEP 6 : Repeat i from 0 to n an j from 0 to n and check condition if i<=j true or not
if true print else leave free space
STEP 7 : If row number and coloumn number is different then print suitable
message
STEP 8 : END
Variable description:
Algorithm
STEP 1 : START
Variable description:
1 c int Counter
2 s String Accepting value
import java.util.*;
class Anagrams
{ int c = 0;
void input()throws Exception
{ Scanner sc = new Scanner(System.in);
System.out.print("Enter a word : ");
String s = sc.next();
System.out.println("The Anagrams are : ");
display("",s);
System.out.println("Total Number of Anagrams =
"+c);
}
void display(String s1, String s2)
{
if(s2.length()<=1)
{
c++;
System.out.println(s1+s2);
}
else
{
for(int i=0; i<s2.length(); i++)
{
String x = s2.substring(i, i+1);
String y = s2.substring(0, i);
String z = s2.substring(i+1);
display(s1+x, y+z); }
}
}
public static void main(String args[])throws
Exception
{
Anagrams ob=new Anagrams();
ob.input();
}
}
Algorithm
STEP 1 : START
STEP 2 : [Check for the underflow]
if(front=NULL and rear=NULL)
Display(“Queue Underflow”)
STEP 3 : [Delete an element at the front end]
Display(“Deleted-”, ar[front])
if(front =rear)
front=NULL and rear= NULL
else
front++
STEP 4 : [Delete an element at the rear end]
Display(“Deleted-”, ar[rear])
if(front =rear)
front=NULL and rear= NULL
else
rear--
STEP 5 : [Set the pointer if Underflow]
if(front =NULL and rear= NULL)
front=0 and rear=0
[insert the first element]
ar[front]=n
STEP 6 : [Insert the element in the Dqueue at rear end]
if(rear=size-1)
Display(“Queue overflow at rear end”)
else
rear++
ar[rear]=n
STEP 7 : [Insert the element in the Dqueue at front end]
if(front=0)
Display(“Queue overflow at front end”)
else
--front
ar[front]=n
STEP 8 : Display the elements form front to rear
STEP 9 : END
import java.util.*;
class DeQueue
{ int size=5,front=-1,rear=-1;
int ar[]= new int[size];
void front_delete()//delete element function
{ if(front==-1 && rear==-1)//checking if queue is empty
System.out.println("Queue Underflow");
else
{ System.out.println("\nDeleted- |"+ar[front]+"| ");
if(front==rear)
front=rear=-1;
else
front++; }}
void rear_delete()//delete element function
{ if(front==-1 && rear==-1)//checking if queue is empty
System.out.println("Queue Underflow");
else
{ System.out.println("\nDeleted- |"+ar[rear]+"| ");
if(front==rear)
front=rear=-1;
else
rear--; }}
void rear_insert(int n)//insert element function
{ if(rear==size-1)
System.out.println("Queue overflow at rear end");
else
{ if(front==-1 && rear==-1)
front=rear=0;
else
rear++;
ar[rear]=n; }}
void front_insert(int n)//insert element function
{ if(front==0)
System.out.println("Queue overflow at front end");
else
{ if(front==-1 && rear==-1)
front=rear=0;
else
--front;
ar[front]=n; }}
void display()//display queue function
{ if(front==-1&&rear==-1)
System.out.println("Dequeue empty");
else
{
for(int i=front;i<=rear;i++)
System.out.print("|"+ar[i]+"| "); }}}
6 i int Counter
Output:
Entering values in rear 5,4,3,2 & calling display function
Removing value from front (5) & calling display function
Entering value at front (6) & calling display function
Removing value from rear(2) & calling display function
Algorithm
Step 1- START
Step 2- store a highly negative number in the initial cell
Step 3-Sort the elements. Repeat Step 6 for (i=1,2,3…….n)
Step 4- initialize temporary variables
Step 5- Compare the elements backwards.
Step 6- insert the element entered by the user
Step 7- END.
Variable description:
3 i Int Counter
import java.util.*;
class Insertion_sort
{ static void main()//main function
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array");
int l1=sc.nextInt(),temp=0,ptr=0;
int a[]=new int[l1+1];//declaring array
a[0]=-999;//Highly negative number in initial cell
System.out.println("Enter array elements");
for(int i=1;i<=l1;i++)//accepting array
a[i]=sc.nextInt();
//sorting of array
for(int i=1;i<=l1;i++)
{
temp=a[i];
ptr=i-1;
while(a[ptr]>temp)
{
a[ptr+1]=a[ptr];
ptr--;
}
a[ptr+1]=temp;
}
for(int i=1;i<=l1;i++)//displaying array
System.out.print(a[i]+" ");
}
}
Output:
Algorithm
STEP 1: START
STEP 2: Declare an array to store the names of the month, days, dates and calendar
respectively
STEP 3: Accept year, month and days
STEP 4: if leap year adjust the days of February
STEP 5: Find the day and month entered by the user to make the calendar
STEP 6: for i=0 to 4,
STEP 7: for j=0 to 6,
STEP 8: Enter the date in a[i,j]
STEP 9: if the date entered reached the number of days in a month, r=1 and goto
STEP 11 otherwise increase date by 1 and goto step 7 with j=j+1
STEP 10: if dates cannot be added further i=-1 and goto step 6 with i=i+1
STEP 11: Display the array a
STEP 12: END
import java.util.*;
class Calendar_Print
{
static void main()
{
String
days[]={"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRID
AY","SATURDAY"};
String
months[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JUL
Y","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER",};
int dates[]={31,28,31,30,31,30,31,31,30,31,30,31};
int a[][]= new int[5][7];
Scanner sc = new Scanner(System.in);
System.out.println("Enter the year,month and the first
day of the month");
int y=sc.nextInt();//accepting year
String m= sc.next(),d=sc.next();//accepting month and
1st day
if(y%4==0)//checking for leap year
dates[1]++;
int c=0,r=0,s=0,date=1;
for(int i=0;i<12;i++)
{
if(m.equalsIgnoreCase(months[i]))//finding the month
entered
s=i;
}
for(int i=0;i<7;i++)
{
if(d.equalsIgnoreCase(days[i]))//finding the day
entered
c=i;
}
for(int i=0;i<5;i++)
{
int p=0;
for(int j=c;j<7;j++)
{
a[i][j]=date;
if(date<dates[s])//finding if more dates to
enter
{
p++;
date++;
Output: