SAMPAD MONDAL - Java - 13001622032
SAMPAD MONDAL - Java - 13001622032
SAMPAD MONDAL - Java - 13001622032
Mondal Roll–
13001622036
1. // to reverse a string
import java.util.*;
class reverse
String word1="";
l=word.length ();
for (i=l-1;i>=0;i--)
ch=word.charAt(i);
word1=word1+ch;
==================================OUTPUT=========================================
import java.util.*;
class SumOfDigits
return;
int sum = 0;
while (number != 0)
sum += digit;
number /= 10;
}
}
=================================OUTPUT=========================================
import java.util.*;
System.out.println(j);
====================================OUTPUT=======================================
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
import java.util.*;
// Print spaces
System.out.println(" ");
System.out.println("*");
System.out.println();
// Print spaces
{
System.out.println(" ");
System.out.println("*");
System.out.println();
========================================OUTPUT===================================
***
*****
*******
*********
***********
*********
*******
*****
***
*
5. //Java Program to Check whether a String is a Palindrome or not using Recursive Function
import java.util.*;
if(str.length() == 0 || str.length() == 1)
return true;
if(str.charAt(0) == str.charAt(str.length()-1))
return false;
System.out.println(str+" is palindrome");
else
======================================OUTPUT=====================================
mom
mom is palindrome
techno
6. //to separate even and odd numbers from a given set of arrays and print all even numbers first
then odd numbers
class evenodd
System.out.println("Original Array:");
printArray(inputArray);
separateEvenOdd(inputArray);
System.out.println("\nArray after separating even and odd numbers:");
printArray(inputArray);
int left = 0;
left++;
right--;
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
System.out.println();
==========================================OUTPUT=================================
Original Array:
2 5 8 3 12 7 6 10
2 10 8 6 12 7 3 5
7. class Employee
String name;
this.name = name;
this.address = address;
this.salary = salary;
this.jobTitle = jobTitle;
return name;
return address;
return salary;
return jobTitle;
}
public Manager(String name, String address, double salary, String jobTitle, String department)
this.department = department;
public Developer(String name, String address, double salary, String jobTitle, String
programmingLanguage) {
this.programmingLanguage = programmingLanguage;
{
super(name, address, salary, "Programmer", programmingLanguage);
class Company
Manager manager = new Manager("John Manager", "123 Main St", 80000, "Manager", "IT");
Developer developer = new Developer("Alice Developer", "456 Oak St", 70000, "Developer",
"Java");
Programmer programmer = new Programmer("Bob Programmer", "789 Pine St", 75000, "C++");
manager.manageProject();
developer.writeCode();
programmer.writeCode();
=========================================OUTPUT==================================
this.balance = initialBalance;
// Abstract methods
return balance;
// Subclass SavingsAccount
class SavingsAccount extends BankAccount
super(initialBalance);
this.interestRate = interestRate;
@Override
@Override
balance -= amount;
} else
// Subclass CurrentAccount
super(initialBalance);
this.overdraftLimit = overdraftLimit;
@Override
balance += amount;
@Override
{
balance -= amount;
} else
class BankDemo
savingsAccount.deposit(500);
savingsAccount.withdraw(200);
currentAccount.deposit(800);
currentAccount.withdraw(2500);
====================================OUTPUT======================================
Withdrawal: $200.0
Deposit: $800.0
Withdrawal: $2500.0
9. import java.util.ArrayList;
import java.util.List;
class Account
double balance;
this.accountNumber = accountNumber;
this.accountHolder = accountHolder;
this.balance = balance;
}
return accountNumber;
return accountHolder;
return balance;
if (amount > 0)
balance=balance + amount;
} else
}
}
balance= balance-amount;
} else
class Bank
public Bank()
accounts.add(account);
System.out.println("Account added successfully");
if(accountNumber.equals(accountNumber))
System.out.println("--------------");
if (account.getAccountNumber().equals(accountNumber))
{
return account;
return null;
// Create a bank
bank.addAccount(account1);
bank.addAccount(account2);
// Display accounts
bank.displayAccounts();
if (foundAccount != null)
{
foundAccount.deposit(500.0);
foundAccount.withdraw(200.0);
// Remove an account
bank.removeAccount("B456");
bank.displayAccounts();
======================================OUTPUT=====================================
Balance: 1000.0
Balance: 1500.0
Account Number:
A123
Account Holder: John Doe
Balance: 1300.0
Balance: 1500.0
10.
//Variables
this.name = name;
this.id = id;
this.salary = salary;
return name;
return id;
return salary;
// Main method
emp1.setName("Shivam Kumar");
emp1.setId(2022098);
emp1.setSalary(60000.0);
// Print value
=====================================OUTPUT=====================================
11. // Shape.java
class Shape
void draw()
double calculateArea()
return 0.0;
}
// Circle.java
double radius;
Circle(double radius)
this.radius = radius;
@Override
void draw()
System.out.println("Drawing a circle");
@Override
double calculateArea()
}
// Cylinder.java
double height;
super(radius);
this.height = height;
@Override
void draw()
System.out.println("Drawing a cylinder");
@Override
double calculateArea()
}
class Main
circle.draw();
System.out.println();
cylinder.draw();
=======================================OUTPUT====================================
Drawing a circle
Drawing a cylinder