0% found this document useful (0 votes)
37 views

Faculty of Engineering and Technology: Object Oriented Programming /java Lab (CS-453)

This document provides an index of 15 Java programs written for an Object Oriented Programming/Java lab session in the 2021-22 academic year. The programs cover topics like square root calculation, area calculation using classes, if-else statements, loops, sorting, floating point operations, 2D arrays, relational operators, casting, inheritance, constructors, interfaces, and string manipulation. Each program is briefly described and includes sample input/output.

Uploaded by

Akash Chak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Faculty of Engineering and Technology: Object Oriented Programming /java Lab (CS-453)

This document provides an index of 15 Java programs written for an Object Oriented Programming/Java lab session in the 2021-22 academic year. The programs cover topics like square root calculation, area calculation using classes, if-else statements, loops, sorting, floating point operations, 2D arrays, relational operators, casting, inheritance, constructors, interfaces, and string manipulation. Each program is briefly described and includes sample input/output.

Uploaded by

Akash Chak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

FACULTY OF ENGINEERING AND

TECHNOLOGY

Object Oriented
PROGRAMMING /JAVA Lab
(CS-453)

SESSION:-2021-22

Submitted by:- Submitted To:-


Name:- Sameem Ahamad Dr. Abhinav Prakash
Branch:- CSE-2(P1) Srivastava
Roll No:- 200013139090

1
INDEX
Sr PROGRAM Pg no. Signature
no.
1 WAJP to compute Square Root of a given 3-4
number.
2 WAJP to compute the Area of a Room using 5
multiple classes.
3 WAJP that depicts the use of Nested if-else 6-7
statement.
4 WAJP that depicts the use of while loop. 8

5 WAJP for sorting a list of Numbers. 9-10


6 WAJP depicting the Floating Point Arithmetic 11
Operations in Java.
7 WAJP to print multiplication table using do-while 12
loop.
8 WAJP that stating the application of 2-D Array. 13-14
9 WAJP for implementation of Relational 15
Operators.
10 WAJP for illustration of the use of Casting 16
Operations.
11 WAJP illustrating Inheritance(use of ‘Super’
keyword)
12 WAJP illustrating the use of Constructors
13 WAJP implementing interfaces in java
14 WAJP for implementing Alphabetical Ordering of
Strings(String-Manipulation).
15 WAJP for demonstration of Java Expressions

2
LAB-1
Write a Java Program to compute Square Root of a given number.
import java.util.Scanner;
public class FindSquareRootExample1
{
public static void main(String[] args)
{
System.out.print("Enter a number: ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("The square root of "+ n+ " is: "+squareRoot(n));
}
public static double squareRoot(int num)
{
double t;
double sqrtroot=num/2;
do
{
t=sqrtroot;
sqrtroot=(t+(num/t))/2;
}
while((t-sqrtroot)!= 0);
return sqrtroot;
}
}

3
OUTPUT:

4
LAB-2
Write a program to compute the Area of a Room using multiple classes.
class Room
{
float length;
float breadth;

void getdata(float a, float b)


{
length = a;
breadth = b;
}
}
class RoomArea
{
public static void main(String args[ ])
{
float area;
Room room1 = new Room ( );
room1.getdata(14, 10);
area = room1.length * room1.breadth;
System.out.println("Area = " + area);
}
}

OUTPUT:

5
LAB-3
Write a program that depicts the use of Nested if-else statements.
import java.util.Scanner;
class Nested
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the age: ");
int age=sc.nextInt();
System.out.println("Enter the weight: ");
int weight=sc.nextInt();
if(age>=18)
{
if(weight>50)
{
System.out.println("The person is eligible to donate blood");
}
else
{
System.out.println("The person is not eligible to donate blood");
}
}
else
{
System.out.println("Age must be greater than 18");
}
}
}

6
OUTPUT:

7
LAB-4
Write a program that depicts the use of while loop.
public class Whileloopdemo {
public static void main(String args[])
{

int i = 1;

while (i < 6) {
System.out.println("Hello World");
i++;
}
}

OUTPUT:

8
LAB-5
Write a program for sorting a list of numbers.
public class NumberSorting {
public static void main(String args[])
{
int number [] = { 55, 40, 80, 65, 71 };
int n = number.length;
System.out.print("Given list : ");
for (int i = 0; i < n; i++)
{
System.out.print(" " + number[i]);
}
System.out.println("\n");
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (number[i] < number[j])
{
int temp = number[i];
number[i] = number[j];
number[j] = temp;
}
}
}
System.out.println("Sorted list : ");
for (int i = 0; i < n; i++)
{
System.out.println(" " + number[i]);

9
}
System.out.println(" ");
}
}

OUTPUT:

10
LAB-6
Write a program that depicting the floating point operation in java.
public class Floatpoint {
public static void main (String args[]){
float a= 21.5F, b=4.7F;
System.out.println(" a = " +a);
System.out.println(" b=" +b);
System.out.println(" a+b= " +(a+b));
System.out.println(" a-b=" +(a-b));
System.out.println(" a*b=" +(a*b));
System.out.println(" a/b=" +(a/b));
System.out.println(" a%b=" +(a%b));
}
}

OUTPUT:

11
LAB-7
Write a program printing Multiplication Table using do…while loop.
import java.util.Scanner;
class Multiplication_Table4{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int num;
System.out.println("Enter the number: ");
num=sc.nextInt();
int i=1;
do{
System.out.println(num+"x"+i+"="+num*i);
i++;
}while( i<=10);
}
}

OUTPUT:

12
LAB-8
Write a program stating the application of 2-D arrays.
class Multable {
final static int ROWS = 20;
final static int COLOUMNS = 20;
public static void main (String args[]){
int product[][]= new int[ROWS][COLOUMNS];
int ROW, COLUMN;
System.out.println("MULTIPLICATION TABLE");
System.out.println(" ");
int i,j;
for(i=10; i<ROWS; i++)
{
for(j=10; j<COLOUMNS; j++)
{
product[i][j]=i*j;
System.out.print(" " +product[i][j]);
}
System.out.println(" ");
}
}
}

13
OUTPUT:

14
LAB-9
Write a program for implementation of Relational Operations.
public class RelationalOperators {
public static void main (String args[]){
float a= 40.73F, b=48.7F, c = 40.73F;
System.out.println(" a = " +a);
System.out.println(" b=" +b);
System.out.println(" c=" +c);
System.out.println(" a<b= is " +(a<b));
System.out.println(" a>b= is" +(a>b));
System.out.println(" a==b = is" +(a==b));
System.out.println(" a<=b = is" +(a<=b));
System.out.println(" a>=b = is" +(a>=b));
System.out.println(" b!=c is" +(b!=c));
System.out.println(" b== a+c is" +(b==a+c));
}
}

OUTPUT:

15
LAB-10
Write a program for illustration of the use of Casting Operations.
public class Casting {
public static void main(String args[]) {
int i;
float sum;
sum = 0.0F;
for (i = 1; i <= 10; i++) {
sum = sum + 1 / (float) i;
System.out.print("i = " + i);
System.out.println(" Sum = " + sum);
}
}
}

OUTPUT:

16

You might also like