You are on page 1of 25

ADITYA DEGREE COLLEGE Page Noo1

4-1132
Quadatfc Cquation Practical No or
Aim
tOYite Java
a
PAoqram 4hat PYints all YOOts Of Ouoctratie
equation a+bxtC O.

Algovlthm
Step Stat
steP Read abc
step 3 :initiaize de -Cb* B) -4* a*c)
Step 4
initialize
T blaa

Step 5 i d O go to Step 6, e lse qo +o Step8

Step 6 :YlT+Csqnt Cd) 12* a) and =T-CSATtcd)|a*a)

Prints roots oave real and distinct, first root T{


Step
Secend root Y

Step 8 f d0 0 to Step , else a0 to step 10

Print Toots ane real and equal.


SteP
d - d

Step
i m SqrtCd)/2*a
step
maginay irst YOut isY+i im,
Paint ootS ane
(2
Step root is-I im.
and o e Second

Step 13 Stop

DEPARTMENT OF COMPUTER SCIEN


ADITYA DEGREE COLLEGE Page No d62
Date 24-l-3.2
Practical No of

Program
impoYt java. lang. *
imPort dava. util. *.,
tmPoYt dava. io, *
class RootS

Public static void main CString arqs c1)

double T
SCanner S= new Scanner CSystem. in)
System.out, Printin C Enter abc Values "),
double a= S. nertobuble C)
double b S. 0et double c)
double C S . nert Double c),

double d Cb* b)- (u*a¥ c),


f Cd o)

C Roots are veal and equol)7


System.out.PrintAn
TI2-b| Ca*a)
stemout. Printlo C R1= +T)
System. out. Printio C Ra

eise 1F Cd >o)

dut. PrintinC RootS ame real and distinct 9


stem
T C-b+ Math. SqrE Cd) |Cat a),
- C - b - madh.Sqrt Cd))/ (*a),

System.out. Print Ln C R
*

+):,=

System out. Printin Ra= )


3
DEPARTMENT OF cOMPUTER SCIE
ADITYA DEGREE cOLLEGE
Pge No o
Oate 94 t d
Practical No ot

elSe

System. out. frintRnCRootS ame distinct and imaqinany"),

double x -b CoXa) ,
double Y Math .Sqrt C-d) lC>Wa)

System. out.PrintLoC R1-tX + +Y)


X
System.out Printin CR
+

3
output
abiC Values
Enter

53

neal and distinct


Roots are

R -l.O

Ra-.5
1

ADITYA DEGREE cOLLEGE


Page No. ou
Date c12 32
Prime Numbers Practical No 0
Aim orite a Java
integer ahd +hen PAogrann that PromptS he
user for an
Paints out all Prime numbers
inteqer 2 upto +hot

Algorthm
Step START

Step 2 Set c t =O, n= O, i=l, J= I

Step 3 Repeat Step to Step 1 unt i l n< 25

Step 4
Set
ct =0
Step 5
Set
Unti l de=i
Step + +o SteP 8
Step 6 Repeat

i f i l . j ==o hen ct =ct +I


Step
Step 8

hen PTint i
f ct = 2
SteP 9A

n=n+ L
Step D

St ep

ENDD
Step 12

DEPARTMENT OF COMPUTER SCIE


ADITYA DEGREE cOLLEGE

Progyom Practical o o2
imPovt ava io.
impont dava loang. *
impoyt Java util *
ctass Prime

Public Static Void maln C


Strinq aYqs c)
tnt ne 100
CoYCint i-2, in) t+)

Count =0
for Cint d2, J<i jtt)
ifCi 3 -
- o)
Count +t2

3
Cont --O)

SYstem. out. Print Ln Ci + "),

3
3

Out Puut
5,5,4, l1,13, I4t9, 23, 19, 31, 34, 4 43,41153 59,6l,61 Hl13, 983,89n4
ADITYA DEGREE cOLLEGE

Student Class. 15 -23


Aim ovite o Jovo
uo4h
Phoqrorn Create a Studerd closs
tobLoing details

dHall ticket number


ci Student Nome
i) De Portmernt
CYeate n numbeY of Student obsects Ahereo volue 1s
Passed as input to Cons tructor.

Algovithm
Step 1 Start

de fined
SteP 2 import required System Packoqes
Step 3 :Create a clasS Student with Yno, nome moTKS.deportmed

as PAopeTties Ond display C) method

Step 4 Creati a method oisploy to disploy Studert Tno. nome


monks g depzotmert.

Close the closs Student


Step

G Creoi closs Studeptbemo which Contains


Step main

Method
: Crepte obTect for class student
Step

Step Assign ValueS +0 P2oPerties uSing dbTectTererence


call display method @reated in
Step-4 usng
step
obJect

Step D stop

DEPARTMENT OF COMPUTER SCIEN


ADITYA DEGREE COLLEGE

De15-
Praccal
Progroro
irmport Jovo tong *
irnport javo. io. *
class student

int roo,
String mome
double morkS
String dePortnerty
void displayc

System.out. PrirtjoC ROII Number \n:


+Tno)
Systemout. Printio C Name In : "

sustem.out. Pcintio maaks In: +0ame)


"imoxks)
System.out. Prirto C°
Depostment lo:+depostmert)

ctoss Studentpemo

Public Stotic void main C 9tring Ogs t)

Student S-new Student C)


S.Tmo 1Ol
S.name paxdon
S. roants99.9

Sheastenent JAVA
display C

3
Output
Roll nlumber O

Nome Povan
markS 99.9
DRoatrmnt JAVA
DEPARTMENT OF COMPUTE
ADITYA DEGREE cOLLEGE

ate 383 32
HieraYchial nheitance
Aim tOYite Javo PRogYom to implemert
Hierarchia
Tobeyitance

Algorithm

Step StaYt

Yeq uired System de fined Packoaqes


Step impoY t

3 Create a Povent ctass animoal uphich Contains


Step
eat c method which dis play a
message as

eat ing
step y elose +he method of Parert class

Creat first child ctass as do9 inherit the


Step
Pament class
FiYst class ContainS a method baYk ohich
SteP
with display Bomkinq".

close he first child ctass


Step
Creai Se Cond class Contains as Cat& inherit
Step
he Parentclass

child ctass Contalns amethod meno


Step Second
O th disptay meooing

Close he Second child ctosS


Step

recte main Class hierorchial Inherifance


Step Ohere obiects arre to be Created forfrst
chitd ctass Seasmd child class to access
he method
Step 1a StoP DEPARTMENT OF COMPUTER SCIENCE
ADITYA DEGREE CoLLEGE Page o or

Date 38 3-3
Practical to oly

Program
import Java.io.*
imPoYt Java.util. *
ctass animal

void eat C)

System. 6ut. PrinttnC eating.... "))

elass dog ectendS animal

Void bark C)

C
System.out. Println baTKinga e

class cat e tendds animal

void meow c)

Syste out. Pvintn Cmeowing. . "), . .

class hie warichal

Public Stotic void main Strinq avgS C1)

doq d= new doq c)


d.barkC)

DEPARTMENT OF COMPUTER SC
ADITYA DEGREE cOLLEGE Page No. 10

Date a8a-22
Practical No. ou

Cat c =neu cot


C)
C meoD c)
C. eat C)

Output
barking
meouoing
eating

OF C O M P U T E R SCIENCE
DEPARTMENT
ADITYA DEGREE COLLEGE Page No
DiateG-o1 a3
MUItiple Inherttanc Practical tio o5
Aim OYite a Java
Proqram to implemernt muttiple nheritonce
through inter face

Atgoritm

Step Start

SteP 2 import mequired System defined


Package
Define class Student
Step 3 and declare a vaniable roll
number
SteP Define an object to the SyStem defined class
ScanneY
Step Define a method qetrouno c) and reod he Value of
o l number using obiect S.
Detine a method dis payrollno c) and Prit +he value
Step
Of YOU number.

Step t 2Derive a class etemals fvom he base class


Student and declare Vaniobles m and m
Step 8 Define methodd getmarS C) and reod h e values

of maYkS ntw he Vonlables mi, m2 oLSing h e

object S
efine a method display ExternalS C) and Print
Step 9
+he values of maolkS Placed in m and m2
eefine an iter face inteYnalS and dectare the
Step 1p
Nanlabte i'm and assign he Vclue 20.

Declae +he displayInternals c) method thout


Step intertace.
any body in +ne

DEPARTMENT OF COMPUTER SCIENC


1 1 1

ADITYA DEGREE cOLLEGE


Page o 13
ote6-o1-33
Practical o 66

step: APply he
Concept of
Multiple Inheritance
to derive ne class the name ReSults o o the
ctass Exteynats and Inter face InternalS.

step 13 Declae the Vaniable total and define he


method displayTnternalS C) fo Prit Internal marks

Step 14 Define a method display ReSutsc) and


ComoPuute
m l t m2 im and Call he
total = + methods display Younot) ,
displayeiternaluC) displayTnternaS C) and ouso display the total

Value
efine main C) mcthod clasS MuttipleInheritance
Step l5

efine an object to the KeSults class and call


Step
his obiect qetrollnDC) anmd r.qut markst)
the methods hrDug

Step 1t Stop

DEPARTMENT OF COMPUTER SC
ADITYA DEGREE cOLLEGE

Pvoqvam
irnpovt iova io. *,
import Java. lang.*
impoYt dava.util.4
ctass tudent

Scanney Sneuo Scanner C System.in)


int rolinD
void get Rolinot)

SYstem.out.Printin C Enter Rol Number:)


ollno =S.nextInt C)

void disploy Rollno c)

C° Roll Number +Kollno),


System. o u t . Printin

ectendS Student
ctoss Externals

flood mi,m2)
void gct Marks C

bf too Subiccts ),
Astem out. Println (Enter
manks

m S.next Floot C) )
n e c t Floot C)
m2 S

3
/Oid displayExtemals C)

COMPUTER SCIEM
DEPARTMENT OF
ADITYA DrGREE CoLLEGE

System t Pvint tnC" suhiect I


Am)
System ut
P'vit tn C subleet 1tm)>

nter face Interls

void isplaytntevnais c)

elass Result extendS EXtevmls lmplement Tnteymals

tat toto
fublic void displayantenals C)

tim)
System.cut.Pintko c Tntevnals

Void diSplay resulte)

total ml tm2 tm>

display Rounot)
display ENtemalsC)
display Dnternals c)
System.out. Print In C" )
System.out. Pvintln CTOtal :total)

DEPARTMENT OF COMPUTER SsC

ww
ADITYA DEGREE cOLLEGE
ge No 15
A Date &-ol-33
Practical io s
class Multiple Ioberitoance

Public static void main C


Stig args c3)

ResultT=neLo Result C)'


r.getRou no C) '
c t MaY KS )
YdisPoy Resutt C)

Out Put
Enter roll number : oy
Enter marks OtwO SubiectS 85 32

Rou Number y
Subiect -l 5.0b
Subject - 2 396
Internals

Total 45 0

DEPARTMENT OF COMPUTER SCI


ADITYA DEGREE cOLLEGE
Pee No
a5-0t 33
Stxing Opexations
Aim uYite iava Poqram O
demonstvete stving comparisions
uSing and equals method.

Algorithm

Step Start

SteP mpot Nequind System defned Phoxaqes


Cneat a class
Step 33 String Demo which Contaims mai
method.

Step u Ceati String with animation and Save it in str


Step 5 APply to
LoeTdose c) methad to conveyt into uprer Cane
and displa
Omeate Stmin9 lth ANmATlON and Save it
Step 6 înstr2
APPlY to UPPex Cae c) method convevt into touer ca
and
SteP
display.

Apply eplac c) method to eplace o toln A in stvl


Step
and display

Step 9 APPIYenqth C) method and display &enqth.


Step
Comfae strings Strl and Str 2 using equaly
SHP
D using
method ard Puint Equal me otheroise Prit
falSe
StoP
Step

DEPARTMENT OF COMPUTER SCIEN


ADITYA DEGREE cOLLEGE
Pagn o
AA Date 35-ol-32

Aogrom
impovt iavatan. *
import iava. io. *,
ctass String Demo

Public Static void main C


String arqs c3)

String Strl, Str2


Strl animatlon

Str 2 Strl.
toupperCaSe c)
System olt. Printin C' Given String +Strl+ tn Capital lelteYS S:
Str ANIMATION +St2
Str2 Strt to LoweY COsec),
System.out Print Ln C" Given String"+ StY t i n Small letters
is."+ Ser
strl- animation
Str2 Strl.replace Ca', 'A):,
System.out Pr int In C After replocing a woith A "+Str2)
intl StYI.length C°
System.out. Printin Chength ot ven stving"+Strl+ is: "t),

tf CStrl .equalsLstr2)

SHStem. out aint RoC Gien tuoo Stris are equal ")',

etsc

Systum but pintin C"Given


tuoo Stimgs
Strings are not equal')

SCIENCE
DEPARTMENT OF COMPUTER
ADITYA DEGREE COLLEGE
AnMAN Page No. 18
Date 95-ol 23
Practioal No 6
Output
Civen Stvimg animation in
Capltal tellevs is
NtT mATtONN
Civen Stving ANIMATTON n
Sall lettevs ist
Aftev
veplacin9 animatlon
A-AnimAtlon
ength of gven
seving-onimation is
:9
Given Stvimg ave not
cqual

DEPARTMENT OF COMPUTER SCIER


ADITYA DEGREE cOLLEGE
MA ote -02 33
Mulliple Thyeocls Praetical o. of
Aim uwYile a dovo
PApgrarm to dermonstvote
Multiple trreads
Atgovithm
SteP Start

SteP impovt mequimed system defined Packoges


Step 3 Serive a class Even from 4he
Systero defined
class Thread and dcclare he Voniable land x
Step efine a Constructo EVen C) oith a
agument 'n'
OHh nteger data type and assign value dfn
to X

Step 5 Betine a methad and e


runc) peat the Stotemert
System.out Printin Ci) using foY loup oith the
initialization of vatue oith upto1 reaches to
the Value Of with crermentation by2

step 6 erive a clasS Odd rorm he System defined


Class heod and decloare he vaniable x as

integer

Step tine a constructoYOdd oith an


arquUmert
n
of+gPe integer assigo val n +o

SteP 8 e tinne a method run c) and cpeat he


Statement Sstem.aut Printlo Ci) uSing for
toop ol¥h an nitialization of Vatue t
upto eaches tothe value of n oith
ncrement of &.

OF COMPUTER SCIENCE
DEPARTMENT
ADITYA DEGREE cOLLEGE P Poge No 2o
Dwe -0pa 33
Practal os
Step 9 Define main C) method c (ass Even Ddd and
define Ohiect Ho SCanneY ctass S

Step 9efine obiect to class Even and also to class


odd and Call he method Start C) +rough
he obiectS

Step Stop

DEPARTMENT OF COMPUTER SCI


ADITYA DEGREE COLLEGE
Page No a1
Onte 3 03 33
Practical No o

Poranm
imPort Java. lo.
import dava lang. *
class Even extend
S Threadd
int X
Even Cint n)

Public void runC)

forCinti- 2, i =X, i=t+2)

System, out. Printinc),

3
class Odd etends hwead

int
Odd Cint n)

Public Void u n t)

COMPUTER SCIEM
DEPARTMENT OF
ADITYA DEGREE COLLEGE Page No pa
Date 2-D2-93
Practical No 07

PoY Cint i =1, t2 =Xy î=i +2)

System.out Printin Ct)

elassEvenodd

Public Statice Void main ( String arqS CI)

EVen e = new Even C20)

Odd o - ned Odd Cao)

e.Start )
O Start )

Output

2y/6, 8 lD, 12, l6, 18,9 , 1, 35, 79,11 13, 1S, 14, 19

DEPARTMENT OF COMPUTER SCIE


ADITYA DEGREE COLLEGE Page o 3
Ote -3-33
Pac kages (CYeation of packoge) Practicat No 08

Aim cOYite a dava Pvorarnto detnonstrate


(Cveation o Rckage) Packaqe6
govthmi

Step Stavt
Step hoose he namee of he PoCKage

include he Pock.aq COronand S he


Step
Cirst line of COde in ouY Java SourcCe

Pile

The SouYCe Comtains +he classe S,


Step
interfaces ,etc You O ant mclude ín

Packaqe

Compile Creau e Java Packages


Stcp 9

SAcp 6 Stop

COMPUTER SCIE
DEPARTMENT OF
ADITYA DEGREE COLLEGE

3-43
Program

Package P

Public class f ixst

Public void display c)

System.Out. Prmtlo-C FiYst Package )

COMPUTER SCIEM
DEPARTMENT OF
ADITYA DEGREE COLLEGE

Ote 3 3
Packagc CCotection) Practeel o o

b wvite Tov Paograrn execution of Poackoqe


Oime

lgovi4ho

Step COYite a TavNa CDAe

Compile ne Java Code


SteP
CEea
+heb file.
Step 3

ite he Native method implementation.


Step

Shared dibrony.
Create
SteP 5

Run he Paoqram.
Step

DEPARTMENT OF COMPUTER

You might also like