OOPS - RECORD-1 (1) Kaaviya
OOPS - RECORD-1 (1) Kaaviya
: 211423104269
OUTPUT:
RESULT:
FIBONACCI SERIES
PROGRAM:
a) WITH RECURSIVE FUNCTION
import java.util.Scanner;
public class RecursiveFibonacci {
// Recursive method to calculate Fibonacci
public static int fibonacci(int n) {
if (n <= 1)
{
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
OUTPUT:
OUTPUT:
RESULT:
STRING SORTING
PROGRAM:
import java.util.Scanner;
OUTPUT:
RESULT :
OUTPUT :
RESULT :
MATRIX MULTIPLICATION
PROGRAM:
import java.io.*;
import java.util.Scanner;
class GFG {
// Function to print Matrix
static void printMatrix(int M[][], int rowSize, int colSize) {
for (int i = 0; i < rowSize; i++) {
for (int j = 0; j < colSize; j++)
System.out.print(M[i][j] + " ");
System.out.println();
}
}
// Function to multiply two matrices A[][] and B[][]
static void multiplyMatrix(int row1, int col1, int A[][], int row2, int col2, int B[][])
{
int i, j, k;
// Print the matrices A and B
System.out.println("\nMatrix A:");
printMatrix(A, row1, col1);
System.out.println("\nMatrix B:");
printMatrix(B, row2, col2);
// Check if multiplication is possible
if (col1 != row2) {
System.out.println("\nMultiplication Not Possible");
return;
}
// Matrix to store the result
int C[][] = new int[row1][col2];
// Multiply the two matrices
for (i = 0; i < row1; i++) {
for (j = 0; j < col2; j++) {
for (k = 0; k < col1; k++)
C[i][j] += A[i][k] * B[k][j];
}
}
// Print the result
System.out.println("\nResultant Matrix:");
printMatrix(C, row1, col2);
}
// Driver code
public static void main(String[] args) {
OUTPUT :
RESULT :
PALINDROME PROGRAM
PROGRAM:
import java.util.Scanner;
public class PalindromeCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scanner.nextLine();
scanner.close();
// Remove spaces and convert to lowercase
String cleanedInput = input.replaceAll("\\s+", "").toLowerCase();
if (isPalindrome(cleanedInput)) {
System.out.println(input + " is a palindrome.");
} else {
System.out.println(input + " is not a palindrome.");
}
}
OUTPUT :
RESULT :
OUTPUT :
RESULT :
Distance.java
package distanceconversion;
import java.util.Scanner;
miles = km * 0.621371;
System.out.println(km + " km is equal to " + miles + " miles");
}
}
Timer.java
package timeconversion;
import java.util.Scanner;
}
}
Converter.java
import currencyconversion.Currency;
import distanceconversion.Distance;
import timeconversion.Timer;
import java.util.Scanner;
do {
System.out.println("1. Dollar to Rupee");
System.out.println("2. Rupee to Dollar");
System.out.println("3. Euro to Rupee");
System.out.println("4. Rupee to Euro");
System.out.println("5. Yen to Rupee");
System.out.println("6. Rupee to Yen");
System.out.println("7. Kilometer to Meter");
System.out.println("8. Meter to Kilometer");
System.out.println("9. Miles to Kilometer");
System.out.println("10. Kilometer to Miles");
System.out.println("11. Hours to Minutes");
System.out.println("12. Hours to Seconds");
System.out.println("13. Seconds to Hours");
System.out.println("14. Minutes to Hours");
System.out.println("15. Exit");
System.out.print("Enter your choice: ");
choice = s.nextInt();
switch (choice) {
case 1: c.dollarToRupee(); break;
case 2: c.rupeeToDollar(); break;
case 3: c.euroToRupee(); break;
case 4: c.rupeeToEuro(); break;
case 5: c.yenToRupee(); break;
case 6: c.rupeeToYen(); break;
case 7: d.kmToMeter(); break;
OUTPUT:
RESULT:
class Employee {
String empName;
int empId;
String address;
String emailId;
String mobileNo;
Employee(String empName, int empId, String address, String emailId, String
mobileNo) {
this.empName = empName;
this.empId = empId;
this.address = address;
this.emailId = emailId;
this.mobileNo = mobileNo;
}
public void displayEmployeeDetails() {
System.out.println("Employee ID: " + empId);
System.out.println("Employee Name: " + empName);
System.out.println("Address: " + address);
System.out.println("Email ID: " + emailId);
System.out.println("Mobile No: " + mobileNo);
}
}
switch (choice) {
case 1:
Programmer programmer = new Programmer(name, id, address, email,
mobile, basicPay);
programmer.generatePaySlip();
break;
case 2:
AssistantProfessor assistantProfessor = new AssistantProfessor(name, id,
address, email, mobile, basicPay);
assistantProfessor.generatePaySlip();
break;
case 3:
AssociateProfessor associateProfessor = new AssociateProfessor(name, id,
address, email, mobile, basicPay);
associateProfessor.generatePaySlip();
break;
case 4:
Professor professor = new Professor(name, id, address, email, mobile,
basicPay);
professor.generatePaySlip();
break;
default:
System.out.println("Invalid choice.");
}
scanner.close();
}
}
OUTPUT:
RESULT :
PROGRAM:
import java.util.Scanner;
if (top == -1) {
throw new Exception("Stack Underflow"); // Exception for underflow
}
int poppedElement = stackArray[top--]; // Decrement top and return element
System.out.println("Element popped: " + poppedElement);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
switch (choice) {
case 1:
System.out.print("Enter element to push: ");
int element = scanner.nextInt();
stack.push(element);
break;
case 2:
stack.pop();
break;
case 3:
stack.display();
break;
case 4:
System.out.println("Exiting...");
scanner.close();
return; // Exit the program
default:
System.out.println("Invalid option. Please try again.");
}
}
}
}
OUTPUT :
RESULT :