// Experiment 1
// Pratyush Warungase 22AM1031
import java.util.Scanner;
public class Expt1
public static void main(String[] args)
int marks, choice;
Scanner input=new Scanner(System.in);
System.out.println("Enter marks");
marks=input.nextInt();
choice=marks/10;
switch(choice)
case 1:
System.out.println("fail");
break;
case 2:
System.out.println("fail");
break;
case 3:
System.out.println("fail");
break;
case 4:
System.out.println("fail");
break;
case 5:
System.out.println("D grade");
break;
case 6:
System.out.println("C grade");
break;
case 7:
System.out.println("B grade");
break;
case 8:
System.out.println("A grade");
break;
case 9:
System.out.println("A+ grade");
break;
case 10:
System.out.println("fail");
break;
}
// Experiment 2
// Pratyush Warungase 22AM1031
public class Expt2
public static void main(String[]args)
int i,j,count;
for(i=1;i<=1000;i++)
count=0;
for(j=1;j<=i;j++)
if(i%j==0)
count++;
if (count==2)
{System.out.println(i);
}
// Experiment 3
// Pratyush Warungase 22AM1031
void M1()
double area1=l*b;
System.out.println("The area of the rectangle is: "+area1);
void M2()
double area2=s*s;
System.out.println("The area of the square is: "+area2);
void M3()
double perimeter=2*(l+b);
System.out.println("THe perimeter of the square is: "+perimeter);
class Expt3
public static void main (String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of rectangle: ");
double length=sc.nextDouble();
System.out.println("Enter the breadth of the rectangle: ");
double breadth=sc.nextDouble();
System.out.println("Enter the side of the square: ");
double side=sc.nextDouble();
area ob=new area();
ob.M0(length,breadth,side);
ob.M1();
ob.M2();
ob.M3();
}
// Experiment 4
// Pratyush Warungase 22AM1031
import java.util.Scanner;
class Shape{
//Square
void area(float side){
System.out.println("Area of Square="+side*side+"sq.units");
//Rectangle
void area(float length,float breadth){
System.out.println("Area of Rectangle="+length*breadth+"sq.units");
//Circle
void area(double radius){
System.out.println("Area of circle="+3.14*radius*radius+"sq.units");
//Triangle
void area(double base,double height){
System.out.println("Area of triangle="+0.5*base*height+"sq.units");
class Expt4{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the measure of the shapes:\n");
System.out.println("Enter the side of the square: ");
float side=sc.nextFloat();
System.out.println("Enter the length of rectangle: ");
float length=sc.nextFloat();
System.out.println("Enter the breadth of rectangle: ");
float breadth=sc.nextFloat();
System.out.println("Enter theradius of circle: ");
double radius=sc.nextDouble();
System.out.println("Enter the base of Triangle: ");
double base=sc.nextDouble();
System.out.println("Enter the height of Triangle: ");
double height=sc.nextDouble();
Shape Square=new Shape();
Shape Rectangle=new Shape();
Shape Circle=new Shape();
Shape Triangle=new Shape();
Square.area(side);
Rectangle.area(length,breadth);
Circle.area(radius);
Triangle.area(base,height);
}
// Experiment 5
// Pratyush Warungase 22AM1031
import java.util.*;
class Complex {
private double real;
private double imaginary;
public Complex() {
this.real = 0.0;
this.imaginary = 0.0;
public Complex(double real, double imaginary) {
this.real = real;
this.imaginary = imaginary;
public Complex add(Complex num) {
double sumReal = this.real + num.real;
double sumImaginary = this.imaginary + num.imaginary;
return new Complex(sumReal, sumImaginary);
public String toString() {
return "(" + real + " + " + imaginary + "i)";
}
public class Expt5 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the real and imaginary parts of the first complex number:");
double real1 = scanner.nextDouble();
double imaginary1 = scanner.nextDouble();
Complex complex1 = new Complex(real1, imaginary1);
System.out.println("Enter the real and imaginary parts of the second complex number:");
double real2 = scanner.nextDouble();
double imaginary2 = scanner.nextDouble();
Complex complex2 = new Complex(real2, imaginary2);
Complex sum = complex1.add(complex2);
System.out.println("Sum of the complex numbers: " + sum);
scanner.close();
}
// Experiment 6
// Pratyush Warungase
import java.util.Scanner;
class Matrix {
int a[][], t[][];
int r, c, i, j;
void read() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter no. of rows and columns:");
r = sc.nextInt();
c = sc.nextInt();
a = new int[r][c];
System.out.println("Enter First Matrix:");
for (i = 0; i < r; i++) {
for (j = 0; j < c; j++) {
a[i][j] = sc.nextInt();
}
}
sc.close();
}
void display() {
System.out.println("Matrix:");
for (i = 0; i < r; i++) {
for (j = 0; j < c; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
void transpose() {
t = new int[c][r];
for (i = 0; i < c; i++)
for (j = 0; j < r; j++)
t[i][j] = a[j][i];
System.out.println("Transposed Matrix:");
for (i = 0; i < c; i++) {
for (j = 0; j < r; j++)
System.out.print(t[i][j] + " ");
System.out.println();
}
}
}
class Expt6{
public static void main(String[] args)
{
Matrix ob = new Matrix();
ob.read();
ob.display();
ob.transpose();
}
}
// Experiment 7
// Pratyush 22AM1031
import java.util.Scanner;
public class Expt7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string: ");
String str = sc.nextLine();
StringBuffer str1 = new StringBuffer(str);
str1.reverse();
String rev = str1.toString();
if (str.equals(rev)) {
System.out.println(str + " is a palindrome.");
} else {
System.out.println(str + " is not a palindrome.");
}
sc.close();
}
}
// Experiment 8
// Pratyush Warungase 22AM1031
import java.util.Scanner;
class Circle {
protected double radius;
public void acceptRadius() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the radius of the circle: ");
radius = sc.nextDouble();
class Area extends Circle {
private double area;
public void calculate() {
area = 3.14*radius*radius;
public void display() {
System.out.println("Area of the circle is: " +area);
class Volume extends Area {
private double volume;
public void calculateVolume() {
volume = (4.0/3.0)*3.14*radius*radius*radius;
public void displayVolume() {
System.out.println("Volume of the sphere is: " +volume);
public class Expt8 {
public static void main(String[] args) {
Volume sphere = new Volume();
sphere.acceptRadius();
sphere.calculate();
sphere.display();
sphere.calculateVolume();
sphere.displayVolume();
// Experiment 9
// Pratyush Warungase 22AM1031
import java.util.Scanner;
class Student {
protected int roll_no;
public void getnumber() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the roll number: ");
roll_no = sc.nextInt();
public void putnumber() {
System.out.println("Roll number: " +roll_no);
class Test extends Student {
protected float sem1, sem2;
public void getmarks() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the marks for semester 1: ");
sem1 = sc.nextFloat();
System.out.println("Enter the marks for semester 2: ");
sem2 = sc.nextFloat();
public void putmarks() {
System.out.println("Semester 1 Marks: " +sem1);
System.out.println("Semester 2 Marks: " +sem2);
interface Sports {
float score = 0.0f;
void putscore();
class Result extends Test implements Sports {
private float total;
public void display() {
total = sem1+sem2+score;
putnumber();
putmarks();
putscore();
System.out.println("Total Score: " +total);
public void putscore() {
System.out.println("Sports Score: " +score);
public class Expt9 {
public static void main(String[] args) {
Result sr = new Result();
sr.getnumber();
sr.getmarks();
sr.display();