Computer.11 Final
Computer.11 Final
bAsEEt
ClAss: Xi sEC:C2
rOll NO : 24
subJECt : COMPutEr
dAtE PrOGrAM:
[1]:- Write a program in java to accept a day no. between 1 to 366 and year
and the display the corresponding date. Also accept n from user. n is between 1
to 100. Compute and display the future day n days after the given date. Display
the error message if value of day no. n is not within the limit.
Input : Day No. : 50
Year : 2023
n = 25
Output : February 19, 2023
25 Days Later,
March 16, 2023
Input : Day No. : 321
Year : 2023
n = 77
Output : November 17, 2023
77 Days Later,
February 2, 2024
Input : Day No. : 367
Year : 2020
n = 101
Output : Invalid Input
Algorithm:
Class: Next_Date
1. Initialize Variables:
• dt: Initialize an array to store the number of days in each month.
• mn: Initialize an array to store the names of months.
• dy: Initialize an integer variable to represent the day number.
• yr: Initialize an integer variable to represent the year.
• n: Initialize an integer variable to represent the number of days to add.
2. Constructor (Next_Date):
• Initialize dy, yr, and n to zero.
3. Method (accept):
• Accept user input for dy, yr, and n using the Scanner class.
4. Method (check):
• Check the validity of input values:
• Ensure dy is between 1 and 366, yr is between 1900 and 2500, and n
is between 0 and 100.
• Return a boolean value indicating the validity.
5. Method (compute):
• Check the validity of input using the check method.
• If input is valid:
• Initialize ftdy, ftmn, and ftyr to the values of dy, 1, and yr, respectively.
• Use a loop to adjust ftdy, ftmn, and ftyr based on the number of days
and months.
• Display the entered date using the names of months (mn array).
• Calculate and display the next date after adding the specified number
of days.
• If input is not valid, display an error message.
6. Method (isLeapYear):
• Check if a given year is a leap year:
• Use the leap year calculation logic.
• Return a boolean value indicating whether it's a leap year.
7. Main Method (main):
• Create an instance of the Next_Date class.
• Call the accept method to get user input.
• Call the compute method to calculate and display the next date.
8. Execute Program:
• When the program is executed, the main method is called, initiating the
process.
• User input is accepted, and the validity is checked.
• If valid, the program calculates and displays the next date based on the input.
1. stArt
b. MEthOds:
- dAtE(iNt d, iNt M): CONstruCtOr tO iNitiAlizE dAy ANd
MONth
- vOid ACCEPt(): MEthOd tO ACCEPt dAy NO. ANd MONth frOM
thE usEr
- bOOlEAN isvAliddAtE(): MEthOd tO ChECk if thE ENtErEd
dAtE is vAlid
- iNt dAtEtOdAyNO(dAtE dt): MEthOd tO CONvErt dAtE
ObJECt tO dAtE NuMbEr
- vOid disPlAy(): MEthOd tO disPlAy thE dAtE iN dd-MM
fOrMAt
- bOOlEAN islEAPyEAr(iNt yEAr): MEthOd tO ChECk if A
yEAr is A lEAP yEAr
- MAiN(striNG ArGs[]): MAiN MEthOd whErE thE PrOGrAM
EXECutiON stArts
9. ENd
vAriAblE listiNG tAblE:
OutPut:
MAtriX PrOGrAM:
[1] Write a program of 2D array of size m x n. Change the column in circular manner.
Input : m = 3, n = 4
1 2 4 5
9 7 2 1
3 3 4 9
Output :
5 1 2 4
1 9 7 2
9 3 3 4
Algorithm:
1. Class Definition:
• Class Name: Shift
• Data Members:
• int[][] ar: 2D array to store matrix elements.
• int n: Number of rows in the matrix.
• int m: Number of columns in the matrix.
• int i, j: Loop control variables.
2. Constructor:
• Method Signature: Shift(int n1, int m1)
• Parameters:
• n1: Number of rows.
• m1: Number of columns.
• Functionality:
• Initializes the size of the matrix.
3. accept Method:
• Method Signature: void accept()
• Input:
• Takes matrix elements from the user.
• Functionality:
• Uses nested loops to accept matrix elements from the
user.
4. display Method:
• Method Signature: void display()
• Output:
• Displays the original matrix.
• Functionality:
• Uses nested loops to print each element of the matrix.
5. shift Method:
• Method Signature: void shift()
• Functionality:
• Uses nested loops to shift each row's elements to the
right.
• The rightmost element of each row becomes the
leftmost.
6. Main Method:
• Method Signature: public static void main(String[] args)
• Functionality:
• Creates an instance of the Shift class.
• Calls accept to input matrix elements.
• Calls display to show the original matrix.
• Calls shift to perform the shifting operation.
• Calls display again to show the shifted matrix.
Input : m = 4, n = 3
1 7 B
2 9 9
A B 8
F 6 2
Output :
0001 0111 1011
ClAss: wOrds
1. AttributEs:
• sEN (striNG): rEPrEsENts thE iNPut sENtENCE.
2. CONstruCtOr:
• wOrds(striNG s): iNitiAlizEs thE sENtENCE by
triMMiNG lEAdiNG ANd trAiliNG whitEsPACEs.
3. MEthOd: shOw
• iNPuts: NONE
• OutPuts: NONE
• EXECutiON stEPs:
• disPlAy thE OriGiNAl sENtENCE.
• ChECk fOr ".", "?", Or "!" At thE ENd Of thE
sENtENCE, triM thEM, ANd stOrE thEM iN thE
PuNCtuAtiON vAriAblE.
• triM ANy rEMAiNiNG whitEsPACEs frOM thE
sENtENCE.
• CrEAtE A COPy Of thE sENtENCE (k).
• EXtrACt ANd dElEtE wOrds frOM thE COPy (k)
usiNG thE EXtrACtwOrd MEthOd.
• disPlAy thE MOdifiEd sENtENCE with APPENdEd
PuNCtuAtiON.
4. MEthOd: EXtrACtwOrd
• iNPuts: striNG s (CurrENt POrtiON Of thE sENtENCE)
• OutPuts: NONE
• EXECutiON stEPs:
• ChECk if thE sENtENCE (s) CONtAiNs ONly ONE
wOrd (NO sPACE).
• if ONly ONE wOrd, dElEtE thE wOrd usiNG thE
dEl MEthOd.
• if MOrE thAN ONE wOrd, dElEtE thE first wOrd
ANd rECursivEly CAll EXtrACtwOrd ON thE
rEMAiNiNG POrtiON Of thE sENtENCE.
5. MEthOd: dEl
• iNPuts: striNG s (wOrd tO bE dElEtEd)
• OutPuts: NONE
• EXECutiON stEPs:
• APPENd thE wOrd (EXCludiNG thE first ANd
lAst ChArACtEr) tO thE MOdifiEd sENtENCE
(sEN).
6. MEthOd: ChECkENdPuNCtuAtiON
• iNPuts: NONE
• OutPuts: striNG PuNCtuAtiON (PuNCtuAtiON
ChArACtErs At thE ENd Of thE sENtENCE)
• EXECutiON stEPs:
• ChECk fOr ".", "?", Or "!" At thE ENd Of thE
sENtENCE ANd triM thEM.
• stOrE thE triMMEd PuNCtuAtiON ChArACtErs iN
thE PuNCtuAtiON vAriAblE.
7. MAiN MEthOd:
• PrOMPt thE usEr tO ENtEr A sENtENCE.
• CrEAtE AN iNstANCE Of thE wOrds ClAss (Ob) with
thE PrOvidEd sENtENCE.
• CAll thE shOw MEthOd tO disPlAy thE OriGiNAl ANd
MOdifiEd sENtENCEs.
vAriAblE listiNG tAblE:
KAPREKAR NUMBER :
sOurCE COdE :-
AlGOrithM:-
Here's the algorithm of the provided Java program for identifying Kaprekar numbers
within a given range [p, q] and calculating their frequency:
This algorithm provides the basic logic flow of the program for identifying Kaprekar
numbers within the specified range and calculating their frequency.
vdt:-
OutPut:-