Surya SK Computer Practical File
Surya SK Computer Practical File
one column of the array 5. Check if inputted data is valid, else input the data again
Surya SK Computer Practic… 6. Calculate the number of years and subtract the required amount from the number
for(i = 0; i < n; i++)
No. of days - 365 (for a regular year)
{
No. of days - 366 (for a leap year)
c1 =0;c2 = 0;c3 = 0;
Program 1: A program to check whether a two dimensional array is a magic square or not 7. Find the month of the date
for(j = 0; j < n; j++) //for loop to find the sum of each column/row/diagonal
8. Find the number of days in the date
Algorithm: c1 = c1 + ar[j][i];
9. Display the newly formatted date
[Link] for(j = 0; j < n; j++)
10. Stop
2. Create a Scanner object to read the size n of the square array. c2 = c2 + ar[i][j];
3. Create a 2 Dimensional array arr of size n x n. for(j = 0; j < n; j++) Source Code:
4. Prompt the user to input the elements of the array row-wise and fill ar. c3 = c3 + ar[j][j]; import [Link].*;
5. Loop through each row to calculate sum of row. if(c==c1&&c==c2&&c==c3) //checking if all sums are equal public class date
6. Loop through each column to calculate sum of column. continue; {
7. Loop to calculate the sum of the diagonal else public static void main(String args[])
8. Check for every iteration of the loop if sum is equal else print not magic square and exit { {
9. If loop completes, print magic square [Link]("It is not a magic square"); //displaying appropriate message Scanner in = new Scanner([Link]);
10. Stop [Link](0); String month[]= {"","January","February", "March", "April", "May","June", "July","August",
} "September", "October", "November","December"}; //creating an array for the months
Source Code: int dm[]={0,31,28,31,30,31,30,31,31, 30,31,30,31}; //creating an array for the days in a
import [Link].*; }
month
public class magicSquare [Link]("It is a magic square"); //displaying appropriate message
int i,j,c=0,d,days,y,date; //initializing the variables
{ }
[Link]("Enter a data value not less than 5 digits (last 4 digits must be from 1900 to
public static void main(String args[]) }
3000)");
{ d = [Link](); //inputting the data
Scanner in = new Scanner([Link]); while(d<10000||d%10000<1900||d%10000>3000) //checking if data is valid
[Link]("Enter number of rows/columns in array (square array)"); {
int n = [Link](); //input the size of square array [Link]("Invalid data, Re-enter a number");
Output:
int c=0,i,j,c1=0,c2=0,c3=0; //declaring and initializing the variables d = [Link]();
int ar[][] = new int[n][n]; //creating an array }
[Link]("Enter the elements in the array"); y = d%10000; //finding the year
Program 2: A program to calculate a date by accepting a 5+ digit number with the last four
for(i = 0; i < n; i++) days = d/10000; //finding the number of days after the year
digits being the year (must be between the range 1900-3000)
{ if(days>365)
for(j = 0; j < n;j++) Algorithm: {
ar[i][j] = [Link](); //inputting each element into the array 1. Start while(days>365) //finding no. of years after base threshold (regular year)
} 2. Create arrays for each month and number of days in it {
3. Initialize the variables y++;
for(i = 0; i < n; i++) 4. Input the data if(y%4==0)
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 1 of 63 Page 2 of 63 Page 3 of 63 Page 4 of 63
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 5 of 63 Page 6 of 63 Page 7 of 63 Page 8 of 63
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 9 of 63 Page 10 of 63 Page 11 of 63 Page 12 of 63
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 13 of 63 Page 14 of 63 Page 15 of 63 Page 16 of 63
public class AP if(n == 0) 2. Define base class
{ break; 3. Declare instance variables and initialize them using a constructor
public static void main(String args[]) n = n/10; 4. Display the input details
{ } 5. Define subclass which inherits base class using keyword ‘extends’
Scanner in = new Scanner([Link]); String octal = [Link](num); //create octal variable 6. Initialize instance variables of both classes using constructor
int a ,d ,n; // initialize variables. int decimal = [Link](octal, 8); //convert octal to decimal number -base class constructor invoked using ‘super()’
[Link]("Enter the first term of the AP, the common difference and the number of String hexadecimal = [Link](decimal); //convert decimal to hexadecimal 7. Calculate the net pay
Program 9: A java program to convert an octal number to a hexadecimal number
terms"); [Link]("The Hexadecimal Value of "+ octal + " is " + hexadecimal); 8. Display the net pay and the display method of the base class using [Link]()
a = [Link](); // input starting term Algorithm: } 9. Stop
d = [Link](); // input common difference 1. Start }
Source Code:
n = [Link](); // input number of terms 2. Import the util package
//base class code
[Link]("The AP is"); 3. Input an octal number Output:
class Employee
for(int i = 0; i < n; i++) 4. Check if number is octal otherwise ask user to re-enter the number
{
[Link](a + i*d); // display the AP 5. Convert the number to a string
int empNo; //declare instance variables
} 6. Convert the string to a decimal number using .parseInt() function
String empName, empDesig;
} 7. Convert the decimal number to a hexadecimal string using .toHexString() function
Employee(int number, String name, String designation) //initialize instance variables
Output: 8. Convert the string to a number and display it
{
9. Stop
empNo = number;
Source Code: empName = name;
import [Link]; empDesig = designation;
public class conversion }
{ void display() // display information
public static void main(String args[]) {
{ [Link]("Employee Details");
Scanner in = new Scanner([Link]); [Link]("Employee Name: " + empName);
[Link]("Enter an Octal Number = "); [Link]("Employee Number: " + empNo);
int n = [Link](); //input a number [Link]("Employee Designation: " + empDesig);
while(true) }
{ }
if(n%10>7) // check if number is octal
//derived class code
{
class Salary extends Employee // derived class extends base class
[Link]("Not an octal number, re-enter data");
Program 10: A java program to perform net salary calculation using inheritance. {
n = [Link](); . // re-input a number
int basic; // declare instance variables
continue; Algorithm:
double net;
} 1. Start
Salary(int pay, int num, String Name, String Designation) //initialize instance variables
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 17 of 63 Page 18 of 63 Page 19 of 63 Page 20 of 63
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 21 of 63 Page 22 of 63 Page 23 of 63 Page 24 of 63
4. Check if three numbers are prime triplets and return { [Link]("Not Prime Triplets");
- 1 if they are prime triplets Prime ob1 = new Prime(); }
- 0 if they are not prime triplets int n1 = [Link](x); }
5. Create a main function int n2 = [Link](y);
6. Input start limit ‘S’ and end limit ‘L’ in the function int n3 = [Link](z);
7. Create an object to call the methods if(n1 == 1 && n2 == 1 && n3 == 1)
8. Repeat step 9 for i = (S, S+1, S+2, …, L) return (1);
9. Invoke calc(int n) four times by passing values i, i+2, i+4, i+6 and check if either else Output:
- i, i+2, i+6 are all prime return (0);
- i, i+4, i+6 are all prime }
And display them as prime triplets if true public static void main(String args[])
10. Input the 3 integers {
11. Pass the integers into calc(int x, int y, int z) and store the value in ‘p’ Scanner in = new Scanner([Link]);
12. Display the appropriate message based on the value of p [Link]("Enter start and end limit");
13. Stop int S = [Link]();
int L = [Link]();
Source Code:
Prime ob = new Prime();
import [Link].*;
for(int i = S; i <= L; i++)
public class Prime
{
{
int c1 = [Link](i); // checking if ‘i’ is prime
int c2 = [Link](i+2); // checking if ‘i+2’ is prime
public int calc(int n) // method to check whether number is prime or not and return 1 or 0
int c3 = [Link](i+4); // checking if ‘i+4’ is prime
{
int c4 = [Link](i+6); // checking if ‘i+6’ is prime
int c = 0;
if(c1 == 1 && c2 == 1 && c4 == 1) // checking if they are prime triplets
for(int a = 1; a < n; a++)
[Link](i + " " + (i+2) + " " + (i+6) + "\n");
{
if(c1 == 1 && c3 == 1 && c4 == 1) // checking if they are prime triplets
if(n%a==0)
[Link](i + " " + (i+4) + " " + (i+6) + "\n");
Program 12: A program to print all prime triplets within a given range and check if the inputted c++;
}
numbers are a prime triplet using methods. }
if(c == 1) [Link]("Enter 3 integers");
Algorithm:
return (1); int n1 = [Link]();
1. Start
else int n2 = [Link]();
2. Create method ‘calc(int n)’ to check if an inputted number is a prime
return (0); int n3 = [Link]();
- return 1 if prime
} int p = [Link](n1,n2,n3);
- return 0 if not prime
if(p == 1 && n2 == n1+2 && n3 == n1+6 || p == 1 && n2 == n1+4 && n3 == n1+6)
3. Create an overloaded function calc(int x, int y, int z) to check if the three inputted numbers public int calc(int x, int y, int z) //method to check whether inputted numbers are prime
[Link]("Prime Triplets");
are prime by calling calc(int n) inside it triplets
else
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 25 of 63 Page 26 of 63 Page 27 of 63 Page 28 of 63
char caseconvert(char ch) //method to convert case of letter 6. Function ‘void sortword()’ used to sort the word in alphabetical order using the following
Program 13: A program to perform string operations using recursive technique { methodology
if([Link](ch)) 7. Repeat step 8 for i = (65, 66, 67, …, 90)
Algorithm: return [Link](ch); 8. Repeat step 9 for j = (0, 1, …, len-1)
1. Start if([Link](ch)) 9. If character at index j = i, add it to the new word
2. Declare instance variables return [Link](ch); 10. Display the sorted word
3. Create a default constructor to initialize instance variables with default values else 11. Create main function to call the other functions
4. Method ‘void inputword()’ used to input a word return(ch); 12. Stop
5. Method ‘char caseconvert(char ch)’ to convert a character to uppercase if it is lowercase and }
vice-versa, then return it. Source Code:
void recchange(int i) // recursive method to convert case of all letters in word
6. Method ‘void recchange(int i)’ used to convert characters of the entire word through recursion import [Link].*;
{
7. Create an object public class SwapSort
Change ob = new Change();
8. Check the following condition and perform appropriate tasks {
if(i == 0)
- If i = 0, then print the converted string and exit the program String wrd, swapwrd, sortwrd; // declare instance variables
{
- Else, invoke caseconvert(char ch) by passing the character at the index of the string i-1 int len;
[Link]("Case Converted String: " + newstr);
and add it to the new string. Call void recchange(int i) by passing the value (i-1). SwapSort() //initialize instance variables
[Link](0);
9. Stop {
}
wrd = ""; swapwrd = ""; sortwrd = "";
Source Code: else len = 0;
import [Link].*; { }
class Change newstr = [Link]([Link](i-1)) + newstr; void readword() //method to input a word
{ recchange(i-1); {
String str, newstr; // declare instance variables } Scanner in = new Scanner([Link]);
int len; } [Link]("Enter a word in uppercase");
Change() //initialize instance variables } wrd = [Link]();
{ }
str = ""; Output:
void swapchar() // method to swap first and last character of word
newstr = ""; Program 14: A program to perform string operations using methods {
len = 0; len = [Link]();
} Algorithm: swapwrd = [Link](len-1) + [Link](1,len-1) + [Link](0);
void inputword() 1. Start [Link]("Swapped Word:" + swapwrd);
{ 2. Declare instance variables }
Scanner in = new Scanner([Link]); 3. Create default constructor to initialize instance variables with default values. void sortword() // method to sort the word in alphabetical order
[Link]("Enter a word"); 4. Function ‘void readword()’ used to input a word in uppercase {
str = [Link](); //input a word 5. Function ‘void swapchar()’ used to swap the first and last letter of the word and add it to a for(int i = 65; i <= 90; i++)
len = [Link](); // find length of word new string {
} for(int j = 0; j < len; j++)
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 29 of 63 Page 30 of 63 Page 31 of 63 Page 32 of 63
if([Link](j) == (char)i) 4. String function ‘pop()’ used to remove an element from the stack }
sortwrd = sortwrd + (char)i; -check if stack is empty then return $$ void display() // display elements present in stack
} -else return the popped element {
[Link]("Sorted word:" + sortwrd); // display the sorted word 5. Void function ‘display()’ used to display the elements in the register [Link]("Register Names");
} 6. Stop for(int i = 0; i <= top; i++)
public static void main(String args[]) // main method to call all functions [Link](stud[i]);
{ Source Code: }
SwapSort ob = new SwapSort(); public class Register }
[Link](); {
[Link](); int top, cap; // declare capacity and stack pointer
[Link](); String stud[] = new String[100]; // create the stack
} Register(int max)
} {
top = -1; // set initial stack pointer as -1 Output:
cap = max; // set capacity of stack equal to max
Output:
}
void push(String n) // add an element to the top of stack
{
if(top == cap - 1)
[Link]("OVERFLOW"); // display overflow if stack is full
else
{
++top;
stud[top] = n;
}
}
String pop() // remove an element from the stack
{
if(top == -1)
Program 15: A program to perform stack operations return("$$"); // return $$ if stack is empty
Algorithm: else
1. Start {
2. Initialize the stack, stack pointer and stack capacity String pop = stud[top];
3. Void method ‘push(String n)’ used to add an element to the stack --top;
-check if stack is full then display OVERFLOW return(pop); // return element removed from stack
-else add the name }
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 33 of 63 Page 34 of 63 Page 35 of 63 Page 36 of 63
rear = -1; // set rear pointer as -1 void Display() // display the elements of the queue Algorithm:
} { 1. Start
double ele[] = new double[lim]; // create the queue for(int i =0; i < lim; i++ ) 2. Create method ‘boolean isWondrous(int ar[][])’
void pushVal(double v) // add an element to the rear end of the queue [Link](ele[i]+ " "); 3. Initialize instance variables and boolean array
{ } 4. Repeat step 5 for i = (0, 1, 2, …, n-1) and then check if row or column sum is not equal to the
if(rear == lim - 1) } required sum and return false.
[Link]("SHELF IS FULL"); // display full if queue is full 5. Initialize variables for row and column sum and Repeat step 6 for j = (0, 1, 2, …, n-1)
else Output: 6. Check the following conditions and return the appropriate value
{ - If element at the index (i,j) of the array is more than n*n or less than 1 return false
if(front == -1 && rear == -1) - If element is already in array, return false
{ Then, mark the element as present in the array and add the element to the row and column sum
front = 0; 7. Create main function
rear = 0; 8. Input elements of double dimensional array
Program 16: A program to perform queue operations } 9. Call method isWondrous(int ar[][])
else 10. Display appropriate message
Algorithm:
rear++; 11. Stop.
1. Start
ele[rear] = v;
2. Initialize the queue, queue capacity, front and rear of queue Source Code:
}
3. Void method ‘void pushVal(double v)’ used to add an element to the queue import [Link].*;
}
-check if queue is full then display OVERFLOW
double popVal() // remove an element from the rear end of the queue public class Wondrous
-else add the number
{ {
4. String function ‘double popVal()’ used to remove an element from the queue
if(rear == -1) public boolean isWondrous(int ar[][])
-check if queue is empty then return -999.99
return(-999.99); // return 999.99 if queue is empty {
-else return the popped element
else int n = [Link];
5. Void function ‘Display()’ used to display the elements in the queue
{ double Sum = 0.5 * n * (n*n + 1); // find the required sum of each row/column
6. Stop
double d = ele[rear]; boolean seenAr[] = new boolean[n*n]; //create double dimensional array of order n x n
Source Code: if(rear == front) for (int i = 0; i < n; i++)
public class Shelf { {
{ rear = -1; int rSum = 0, cSum = 0;
int lim; // declare capacity of queue front = -1;
int front; // declare front pointer of queue } for (int j = 0; j < n; j++)
int rear; // declare rear pointer of queue else {
Shelf(int n) rear--; if (ar[i][j] < 1 || ar[i][j] > n*n) // check whether number is in range 1 to n*n
{ return(d); // return removed element return false;
lim = n; // set capacity equal to n } Program 17: A program to check whether an array is a wondrous square or not. if (seenAr[ar[i][j] - 1])
front = -1; // set front pointer as -1 } return false;
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 37 of 63 Page 38 of 63 Page 39 of 63 Page 40 of 63
seenAr[ar[i][j] - 1] = true; 8. If minimum value of row is less than the element at the index (k, col) of the array, go back to }
rSum = rSum + ar[i][j]; // accumulate the row sum with the element in index i,j step 4.
cSum = cSum + ar[j][i]; // accumulate the column sum with the element in index j,i 9. If k = n, display value of saddle point if (k == n)
} 10. Stop {
if (rSum != Sum || cSum != Sum) // check if row and column sum is equal to the required [Link]("Value of Saddle Point " + min_row); //display saddle point
Source Code:
sum }
import [Link].*;
return false; }
class Saddle_Point
} if(k != n)
{
return true; [Link]("No saddle point");
public static void main(String[] args)
} }
{
public static void main(String args[]) }
Scanner in = new Scanner([Link]);
{ Output:
[Link]("Enter n: ");
Scanner in = new Scanner([Link]);
int n = [Link]();
[Link]("Enter n: ");
int a[][] = new int[n][n]; // create double dimensional array of order n x n
int n = [Link]();
int k = 0;
int a[][] = new int[n][n]; // create double dimensional array of order n x n
[Link]("Enter elements of the matrix: "); // input elements of array
[Link]("Enter elements of the matrix: "); for (int i = 0; i < n; i++)
for (int i = 0; i < n; i++) // input elements of array {
{ for (int j = 0; j < n; j++)
for (int j = 0; j < n; j++) a[i][j] = [Link]();
a[i][j] = [Link](); }
Program 18: A program to find the saddle point in a matrix
} for (int i = 0; i < n; i++)
Algorithm: {
Wondrous ob = new Wondrous();
1. Start int min_row = a[i][0], col = 0;
boolean wondrous = [Link](a);
2. Input value of n for (int j = 1; j < n; j++) // find minimum value of row
if (wondrous) // check if array is wondrous or not 3. Input elements of double dimensional array of order n*n {
[Link]("Yes, it represents a wonderous square"); 4. Repeat step 5,7 and 9 for i = (0, 1, 2, …, n-1) if (min_row > a[i][j])
else 5. Initialize variables for min value of row and its column number and Repeat step 6 for j = (0, {
[Link]("Not a wonderous square"); 1, 2, …, n-1) min_row = a[i][j];
} 6. Check the following condition and do the appropriate task col = j; // find column number of minimum value of row
} - If minimum value of the row is more than the element at index (i,j) of the array }
> minimum value is equal to the element }
Output: for (k = 0; k < n; k++)
> the column number is j
7. Repeat step 8 for k = (0, 1, 2, …, n-1) {
if (min_row < a[k][col]) // check if minimum value of row is maximum value of column
break;
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 41 of 63 Page 42 of 63 Page 43 of 63 Page 44 of 63
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 45 of 63 Page 46 of 63 Page 47 of 63 Page 48 of 63
int ar[][] = new int[n][m]; // create double dimensional array or order n x m 3. Overload function ‘void area(int b, int h)’ to find area of triangle and display it
int i,j,rSum1 = 0, rSum2 = 0, cSum1 = 0, cSum2 = 0, Sum = 0; // initialize accumulators 4. Overload function ‘void area(double r)’ to find area of circle and display it
[Link]("Enter elements of the matrix: "); 5. Create main function
for (i = 0; i < n; i++) 6. Input side of square; base and height of triangle; and radius of circle
{ 7. Create object
for (j = 0; j < m; j++) 8. Invoke area(int n) by passing value of side of square
ar[i][j] = [Link](); 9. Invoke area(int b, int h) by passing value of base and height of triangle
} 10. Invoke area(double r) by passing value of radius of circle
Program 21: A program to find the sum of the boundary elements of a two dimensional array 11. Stop
for(i = 0; i < n; i++)
Algorithm: { Source Code:
1. Start cSum1 = cSum1 + ar[i][0]; // accumulate sum of first column import [Link].*;
2. Input [Link] rows and columns cSum2 = cSum2 + ar[i][m-1]; // accumulate sum of last column public class Shapes
3. Create integer double dimensional array and input its elements } {
4. Initialize accumulator variables for boundary row and column sums for(j = 0; j < m; j++) void area(int n) // method to find area of square
5. Repeat step 6 for i = (0, 1, 2, …, n-1) { {
6. Accumulate both column sums rSum1 = rSum1 + ar[0][j]; // accumulate sum of first row int a1 = n*n;
- cSum1 = cSum1 + ar[i][0] rSum2 = rSum2 + ar[n-1][j]; // accumulate sum of last row [Link]("Area of square: " + a1);
- cSum2 = cSum2 + ar[i][m-1] } }
7. Repeat step 8 for j = (0,1,2, …, m-1) //remove repeating elements and display void area(int b, int h) // overloaded method to find area of triangle
8. Accumulate both row sums Sum = rSum1 + rSum2 + cSum1 + cSum2 - ar[0][0] - ar[0][m-1] - ar[n-1][0] - ar[n-1][m-1]; {
- rSum1 = rSum1 + ar[0][j] [Link]("Sum of Boundary elements: " + Sum); double a2 = 0.5*b*h;
- rSum2 = rSum2 + ar[n-1][j] } [Link]("Area of triangle: " + a2);
9. Add all sums and remove repetitions of corner elements } }
10. Display boundary sum void area(double r) //overloaded method to find area of circle
11. Stop {
double a3 = 22.0/7.0 * r * r;
Source Code: [Link]("Area of circle: " + a3);
import [Link].*; }
public class Bound_Sum public static void main(String args[])
{ Output:
{
public static void main(String args[]) Scanner in = new Scanner([Link]);
{ [Link]("Enter Side of square");
Program 22: A program to find area of 3 shapes using method overloading
Scanner in = new Scanner([Link]); int n = [Link](); // input side of square
[Link]("Enter no of rows and columns"); Algorithm: [Link]("Enter Base and Height of Triangle");
int n = [Link](); 1. Start int b = [Link](); // input base of triangle
int m = [Link](); 2. Create function ‘void area(int n)’ to find area of square and display it int h = [Link](); // input height of triangle
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 49 of 63 Page 50 of 63 Page 51 of 63 Page 52 of 63
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 53 of 63 Page 54 of 63 Page 55 of 63 Page 56 of 63
Source Code: new_word = new_word + 'i'; 5. Method ‘void day_to_date()’ used to convert the day to a date using the following
import [Link].*; else if([Link](i) == 'i') methodology
public class Encode new_word = new_word + 'o'; - Create an integer array of 12 elements, each having [Link] days from January to
{ else if([Link](i) == 'o') December
String word, new_word; //declare instance variables new_word = new_word + 'u'; - Check if year is a leap year, if it is, change February’s day count from 28 to 29
int length; else if([Link](i) == 'u') - Repeat while number of days - ar[i] > 0
Encode() // constructor to initialize instance variables new_word = new_word + 'a'; > n = n - ar[i]
{ else > m++
word = ""; new_word = new_word + [Link](i); // add character to new word if not vowel > i++
new_word = ""; } - Day of the date = n
length = 0; } 6. Method ‘void display()’ used to display the date
} void display() // display the original and encrypted word 7. Create main function
void acceptWord() // input a word { 8. Create object
{ [Link]("Original Word: "+word); 9. Invoke the functions
Scanner in = new Scanner([Link]); [Link]("Encrypted Word: " + new_word); 10. Stop
[Link]("Enter a word"); }
Source Code:
word = [Link](); public static void main(String args[])
import [Link].*;
} {
public class Convert
void nextVowel() // method to convert vowels to their subsequent vowel Encode ob = new Encode(); // create object and call methods
{
{ [Link]();
int n,d,m,y; // declare instance variables
length = [Link](); [Link]();
Convert() // constructor to initialize instance variables
for(int i = 0; i < length; i++) [Link]();
{
{ }
n = 0;
if([Link](i) == 'A') }
d = 0;
new_word = new_word + 'E';
m = 0;
else if([Link](i) == 'E')
y = 0;
new_word = new_word + 'I';
}
else if([Link](i) == 'I')
Program 25: A program used to convert a day number and year into a date using methods void accept() // input day number and year
new_word = new_word + 'O';
{
else if([Link](i) == 'O')
Algorithm: Scanner in = new Scanner([Link]);
new_word = new_word + 'U';
1. Start [Link]("Enter day number and year");
else if([Link](i) == 'U')
2. Declare instance variables n = [Link]();
new_word = new_word + 'A'; Output:
3. Create default constructor to initialize instance variables with default values y = [Link]();
else if([Link](i) == 'a')
4. Method ‘void accept()’ used to input day and year number and check if day number is valid while(n < 1 || n > 365)
new_word = new_word + 'e';
through the following methodology {
else if([Link](i) == 'e')
- if day number is more than 365 or less than 1, ask user to re-input
[Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29 [Link] 30/06/2025, 18:29
Page 57 of 63 Page 58 of 63 Page 59 of 63 Page 60 of 63