Q1
class Number {
int num;
Number(int n) {
num = n;
void Reverse() {
int rev = 0, temp = num;
while (temp != 0) {
int digit = temp % 10;
rev = rev * 10 + digit;
temp /= 10;
System.out.println("Original Number: " + num);
System.out.println("Reversed Number: " + rev);
public static void main(String[] args) {
Number n = new Number(34521);
n.Reverse();
}
Q2
class Largest {
void findLargest(int a, int b, int c) {
int max;
if (a >= b && a >= c)
max = a;
else if (b >= a && b >= c)
max = b;
else
max = c;
System.out.println("Largest Number is: " + max);
public static void main(String[] args) {
Largest obj = new Largest();
obj.findLargest(25, 87, 64);
Q3
class Student {
String name;
int rollNo;
double fees;
Student(String n, int r, double f) {
name = n;
rollNo = r;
fees = f;
void display() {
System.out.println("Name: " + name);
System.out.println("Roll No: " + rollNo);
System.out.println("Fees: " + fees);
System.out.println("---------------------");
public static void main(String[] args) {
Student s1 = new Student("Rahul", 101, 25000);
Student s2 = new Student("Priya", 102, 30000);
s1.display();
s2.display();
}
Q4
class Account {
String name, accType;
int accNo;
double balance;
Account(String n, String type, int no, double bal) {
name = n;
accType = type;
accNo = no;
balance = bal;
void deposit(double amount) {
balance += amount;
System.out.println("Amount Deposited: " + amount);
System.out.println("Updated Balance: " + balance);
void balance() {
System.out.println("Current Balance: " + balance);
void interest(double rate, int years) {
if (accType.equalsIgnoreCase("Saving")) {
double ci = balance * Math.pow((1 + rate / 100), years) - balance;
System.out.println("Compound Interest for " + years + " years: " + ci);
} else {
System.out.println("Current Account: No Interest Applicable");
void withdraw(double amount) {
if (balance - amount < 0) {
System.out.println("Insufficient Balance!");
} else {
balance -= amount;
System.out.println("Amount Withdrawn: " + amount);
System.out.println("Remaining Balance: " + balance);
// Check for Current account limit
if (accType.equalsIgnoreCase("Current") && balance < 5000) {
System.out.println("Balance below 5000! Service charges applied.");
balance -= 200; // example service charge
System.out.println("After Service Charge Balance: " + balance);
public static void main(String[] args) {
Account saving = new Account("Amit", "Saving", 1001, 10000);
Account current = new Account("Rohit", "Current", 1002, 6000);
System.out.println("\n--- Saving Account ---");
saving.deposit(2000);
saving.interest(5, 2);
saving.withdraw(3000);
saving.balance();
System.out.println("\n--- Current Account ---");
current.deposit(1000);
current.withdraw(2500);
current.balance();