Oops
Oops
Operators
int a = 10, b = 5;
System.out.println("Arithmetic Operations:");
System.out.println("\nRelational Operations:");
System.out.println("\nLogical Operations:");
System.out.println("\nBitwise Operations:");
int c = 10;
System.out.println("\nTernary Operation:");
System.out.println("\nShift Operations:");
2a.Salary
import java.util.Scanner;
double bs = scanner.nextDouble();
double hra = 0, da = 0, gs;
da = 0.80 * bs;
da = 0.90 * bs;
da = 0.95 * bs;
} else {
scanner.close();
return;
gs = bs + hra + da;
scanner.close();
2b.menudriven
import java.util.Scanner;
do {
System.out.println("1. Factorial");
System.out.println("4. Exit");
choice = sc.nextInt();
switch (choice) {
case 1:
num = sc.nextInt();
long fact = 1;
fact *= i;
break;
case 2:
num = sc.nextInt();
if (num <= 1) {
isPrime = false;
} else {
if (num % i == 0) {
isPrime = false;
break;
if (isPrime)
else
break;
case 3:
num = sc.nextInt();
if (num % 2 == 0)
else
break;
case 4:
break;
default:
sc.close();
}
}
2c.pattern
int rows = 5;
System.out.print(" ");
System.out.print(j);
System.out.print(j);
System.out.println();
3a.no. of 2s
import java.util.Scanner;
int count = 0;
while (num > 0) {
if (num % 10 == 2) {
count++;
num /= 10;
return count;
if (number < 0) {
} else {
scanner.close();
3b.fibonacci
int n = 10;
int a = 0, b = 1;
int next = a + b;
a = b;
b = next;
4a.parameter books
class Book {
String title;
String author;
double price;
Book() {
price = 0.0;
System.out.println("Default Constructor:");
printDetails();
this.title = title;
this.author = author;
this.price = 0.0; // Default price
printDetails();
this.title = title;
this.author = author;
this.price = price;
printDetails();
void printDetails() {
4b.parameter accounts
class Accounts {
String accNo;
double balance;
Accounts(String accNo, double balance) {
isValid = false;
if (balance < 0) {
isValid = false;
if (isValid) {
this.accNo = accNo;
this.balance = balance;
printDetails();
} else {
void printDetails() {
5a.sport extend
class Sports {
void play() {
void play() {
void play() {
void play() {
}
}
s1.play();
s2.play();
s3.play();
5b.book details
class Publisher {
String name;
Publisher(String name) {
this.name = name;
void display() {
String title;
double price;
Book(String name, String title, double price) {
super(name);
this.title = title;
this.price = price;
void display() {
b.display();
6.calculate interest
interface Transaction {
double balance;
SavingsAccount(double balance) {
this.balance = balance;
}
balance += amount;
balance -= amount;
} else {
void displayBalance() {
double balance;
CurrentAccount(double balance) {
this.balance = balance;
balance += amount;
balance -= amount;
} else {
void displayBalance() {
class RateOfInterest {
System.out.println("Interest for ₹" + balance + " at " + rate + "% for " + years + " years is ₹" +
interest);
sa.deposit(1000);
sa.withdraw(2000);
sa.displayBalance();
CurrentAccount ca = new CurrentAccount(6000);
ca.deposit(1500);
ca.withdraw(5000);
ca.displayBalance();
7.zipcode
import java.util.*;
CityNotFoundException(String message) {
super(message);
class City {
City() {
cityMap.put(110001, "Delhi");
cityMap.put(400001, "Mumbai");
cityMap.put(560001, "Bangalore");
cityMap.put(700001, "Kolkata");
cityMap.put(600001, "Chennai");
}
void findCityByZipCode(int zip) throws CityNotFoundException {
if (cityMap.containsKey(zip)) {
} else {
try {
city.findCityByZipCode(560001);
city.findCityByZipCode(123456);
} catch (CityNotFoundException e) {
System.out.println(e.getMessage());
8.password
import java.util.Scanner;
if (password.length() < 8)
return false;
int digitCount = 0;
for (char ch : password.toCharArray()) {
if (Character.isDigit(ch))
digitCount++;
return false;
return true;
if (isValidPassword(password)) {
} else {
System.out.println("Password invalid.");
9.linkedlist
import java.util.LinkedList;
cities.add("Mumbai");
cities.add("Chennai");
cities.add("Kolkata");
cities.set(1, "Bangalore");
cities.remove("Chennai");
10.copy content
import java.io.*;
try {
int byteData;
out.write(byteData);
}
in.close();
out.close();
} catch (IOException e) {