0% found this document useful (0 votes)
14 views9 pages

Object Oriented Programming Experiments Practical

Uploaded by

16100908rs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views9 pages

Object Oriented Programming Experiments Practical

Uploaded by

16100908rs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

RADHA GOVIND UNIVERSITY

RAMGARH, JHARKHAND
RAMG AR A N D

HARKHA

PRACTICAL
S. NO.
NO. OF EXPERIMENTS PAGE NO.
weide a ova aungam to ind the bibonai ol o2.
Ol Sens usihg Hecursive aud nen
reurstVe
Punc4bn
Wuke a Souwa psogram to mulhph two
02 Jiveu mam'eus 05 0Y

wuit q Jauo Dupgra bor mehod


05 0 6
03 ovw load h aud on sbretot oveuloadh

Wuite a Jouwo ungramto ospay


he emplsyee dalesls uvhg Sanne 04
las
Wue o Java Psuogam hat obeuks
05 awhehera gvn hohg is alindrome
Or n o .

SUBMITTED BY:
HARSH SINHA

UNIVERSITY ROLL:- ..12.535.50.0.2...

SUBJECT: oblutOneniecd
uogrammi'ng(0ops)
COURSE:-..2k.A....SE.

2021-2025

SESSION:-...
SIGNATURE:.
Date
Page O

Expeimend
Aim Hsuite a Jaula ungamdokind he Eibonae-
Seuies using ueirsite_and _non_ILNSLVE
Lunchhs

escipba
PhanasaAelis A Libonatei Senks h -
Jasla is a Sequence o numbets Such hat e y hid-
nunher_ 14 epu/ ko he iun s h e pyezibus turo
numbers
fote o,,1,2,3,5,213, 2,34,

class fib

int a,b.c;
void nonrecursiveint n) //Non recursive function to find the Fibonacci series.

a=0;
b=1
System.out.print(a+ " +b);

c=atb;
while(c=n)
System.out.prin(c);
a=b;
b-c
catb;

int recursive(int n) I/Recursive function to find the Fibonacci series.

if(n=0)
return (0);
if(n=1)
return (1);
else
return(recursive(n-1)+recursive(n-2));

Class that calls recursive and non recursive functions


class fibl1
Date
Page D2

public static void main(String args[)

int n=5;
System.out.println("The Fibonacci series using non recursive is");
/Creating object for the fib class.
fib f-new fib)%
I/ Calling non recursive function oF fib class.
f.nonrecursive(n);
System.out.println("in The Fibonacci series using recursive is");
for(int i=0;i<=n;it+)
/ Calling recursive function of fib class.
int Fl=f.recursive(i);
System.out.print(F1);

E:kalpana> javac fibi. java


Fkalpana>java fib1 5
series
heibonacci
011235 us i ng non recursive is

hsEibonacei series using r e c u r s i ve is


011235
Date
Fege 03

Expeinteod
Ain Huite a Jala Puagtam to muldiply -tuoogiven
Matnces

Daphiao
Matn't mulhphhadhn, ako_Atacon
AAatdces
as Mabnr punduce 2nd he_multplhkabhn # two
Mabples pueduresa ingle _2tn

public class MatrixEx

public static void main(String args[])


creating two matrices
int a[][={{I,1,1},{2,2,2},{3.3.3}}
int b[]l]={{1,1,1},{2,2,2},{3,3,3}}
matrices
creating another matrix to store the multiplication of two
/3 rows and 3 columns
int c[][]-new int[3][3]
of 2 matrices
imultiplying and printing multiplication
for(int i-0;i<3;it+)

for(int j=0:j<3;j++)

cfi]l-0;
for(int k=0;k<3;k++)

clilb+ali][K)*b[k]6):
l/end of k loop
//printing matrix element
System.out.print(c[i]G]+" ");
Wend of j loop
System.out.println(); /new line
Date
Pege O4

E:Nkalpana) javac MatrixEx.java


E:Vkalpana)java HatrixEx
66
12 12 12
18 18 18
Date
Fege 05

Expedimend3
Ain Kuite_a Jauta uegthm_bar rlhnd_aveushadng
and Contuster_Ahadings

ovenloadatng
Mhod 2 4 a bnrep
ak Janin uhich_ure can ueatemulbpde mehed
he 4he_So2e ame inhe am2_Llas,And alMtthoda
holks in Kuett aays
he ase ef Mote han one sheuth in2y
lnshmeLlas

Rgron
Mthododnlaodke
import java.io.*;
class MethodOverloadingEx {

static int add(int a, int b)

return a + b;

static int add(int a, int b, int c)

return a +b+c;

public static void main(String args[])

System.out.println("add() with 2 parameters");


System.out.println(add(4, 6);
System.out.println("add) with 3 parameters");
System.out.println(add(4, 6, 7);
Date
Page 065

E:kalpana)javac Met hodOverloadingEx . java


E:kalpana)java He thodOverload ingEx
add ) vith 2 paraneters

add with 3 paraneters

Lonstuntor ave/oihna
-
public class Student{
instance variables of the class
int id;
String name,
Student(){
System.out.println("this a default constructor");
Student(int i, String n){
id = i;

name=n,

public static void main(Stringl[ args)


lobject creation
Student s =
Student()
new

System.out.println("\nDefault Constructor values: \In");


System.out.println("Student Id: "+s.id+ "\nStudent Name: "+s.name);
System.out.println("\nParameterized Constructor values: \n");
Student student= new Student(10,
"Kalpana");
System.out.println("'Student Id: "+student.id+ "nStudent Name: "+student.name);

EEkalpana>javac Student.java

E:kalpana>java Student
his a default construc tor
values :
Default Cons tructor
Student Id :
Student Nane : rnull

Construct0r values 3
Paraneterized
Student 1d : 10
Student Nane Kalpana
Date.
Page D7

Epelinent4
An uite a Jah uogtomh dplay he
tmplnyee deeuls _usi

LuSed o e t user nput aud ihskhund h he


ah unhl Daskage

import java.util.*;
class EmployeeDetails

public static void main(String args[})

System.out.println("enter name,id,age,salary");Scanner sc=new Scanner(System.in);


String n=sc.next();int i=sc.nextInt(); int a=sc.nextInt();

float s=sc.nextFloat(O;
System.out.println("name is"+n+"idis"+i+"ageis"+a"'salaryis"+s);

E:kalpana>javac Emplo yee Details.java


E:kalpana>java Employee De tails
name, id, age, Salaryy
enter
Socse

123456789
nane is: _Socse
id is 3
age is : 2
salary is:1.23456792E8
Date
Fage 0

EpetiaentL
Ain hlutte a aun ugnm-that heeks_alhethed a a

Smh 1_an_bhtee hat weptrsenk


a mmber_Af_CAaareey_alues
lelindianLA Ehe Meeyse_s6 ha
nme s he vohihal Smg

I/ Class to find whether string is palindrome or not.


class palindrome

public static void main(String args[])

IAccepting the string at run time.


String s=args[0];
String sl="
int lej;
/Finding the length of the string.
le = s.length();

/ Loop to find the of the


reverse string.
forgj=le-1:j>=0j--)
sl=sl+s.charAtg);
/ Condition to find whether two
strings are equal and display the message.
if(s.equals(s1)
System.out.println("String "+s+" is palindrome"); else
System.out.println("String "+s+" is not palindrome");

E:kalpana)javac palindrone .java


E:kalpana>java palindrome kalpana
is not palindrome
String kalpana
E:Nkalpana>jaua palindrone madam
String madan is palindrone

E:kalpana>

You might also like