JAVA Assignment 01
JAVA Assignment 01
Pregvam Code
P vam 0kpub
. ava
/javac Hello Java j
/ HELLO J AVA
Vue
rgyam Code:
Public
class Add Two um
public shaic
veid main Sng l1 arqs)
Systen Dot.printlAneSommation
+noml" and'+
MUm2 +" i"+YCsu lE) ;
O
Oukput
Preqrau
javac Add Two om.i aua
1ava A dd Two om
/> Ane Summahon 10 and 20 iC 0.
de elared
Jova pyogram to Cal culate actoriol
Oalve a-
Uari able.
rogram Cde
poblic
clacc octo rial
publlc
mauSring t)Orqs)
latie void
= 5, act.num ber = l
FnU m lber
hilekemp -hum o)
ber # kemp -num
actnUm ber tack-nom
--
kemp num
is act-nomber)
t
ram Output
Poblic class
pvblie
une actorial
w nom ber
System.
= 5i
0uk.print"lneoctoriol
mUnber + "is:"
actorial number
num) 1
public etalic int attovialint
act- nm
= l;
hile mum o)
act mom
* Um;
ac-nomn
vmacl_num
03.
Oite
Q5Oite a Javs proq vam
Jouo Po
ko Caliulake toctorial value dselared
public
class Clase Hehod-c toviol
puLlic
fatic void oct num int nom)
=num
it methodact-
nombr =I, m eHnod-temp- num
hi le
(memod temp-nuwm o)
=
ac- nmbev mehod-
ock-number
menod
meHhod- Hemp- nUm
menod temp-num
-
acorial
valve nU
yStem
ov.printinlne
+wehod- pch-number)i
rog ra 0.put
04
6. ite a Java prog rau Xo Calente neloriat vaue d a vatiable
v ram Code:
Hemp =;
number i>oi--)
int i
emp= temp4i,
valve q hUwber +
qoctorial
Syslem.ovk.privtln"Ane
ram Cukpuk
I Foclorial CL1-
avac inpvt. 'ava.
utev he nu m ber
Ahe actorial ualve d is: 31416800.
05.
Write a Jan proqam o duslay rhru a numr is odde avan
Yoa Code
mumbv 7.2 0)
ystem. out.pvintlu"Even")
else
0dd")
stem uk. prinhla
vogram Otpuk:
awa 0ddtuen
06
Q8 vi a
ram
Jave "
ode:
tond mari mum a wee num bers.
System.0uk. println
trigt]
tnumbev
;
arq:)
: numl + nd
nom 3
numly num2 & num2> num3))
Larfe. )
nd wmer iute
em.utpiutu xaaf.")
Laa")
raamaput:
/1auac
arOf Mhaee
Doms. hava.
0.
9 write o Java pregvam to Swap tw wmber
P Gde
ublic clase
S Twe ombers
enp 7 numberl;
hu nber mmber2,
nunber 2- tampi
+number 2);
Ofput
//7 javac ap lwo ombers .
jaua
ombers.
Swap lwo
10 2nd nwmber 2.
>let Letmumber:
gnwmaer 2
nd nww.ke: 0.
08.
Q10 toChece shuur a year
Lenp
OiteJava 4
net.
gva sde
public
class ea Year
wF yeav
(yer .
stem.
2012
4--o)&&(year
100 -o) (yeary.At0 = = o)
out. printlYear
ica
){
yearyear.");
o vam Otpu
ur cap2A
2012 ic a lea Year.
09.
QuOrie a Java or ollouwing gading CyRtem
NOTE:
Yam de Pevcen toqe
>= 107. :Grade A
Prog
pvblic
public
clase
saic
vading ystem
Percenge>=40%.
Percenae
>=
:
hge> =80. Gade
60%.
:
Gade C
qmde D
B
A");
oot-print CGvade
tem.
Cys
else
&0 9 pere enlaqe
10)
percentre
D")
ele
System out printloGrade
rcenbae
40 -
percenge <6o)
jawac
java
Grade .
Grading Syctem
Gradiva Syctem
java
10.
Q12. Orite a Java prram to Che haker a number ie diwisille
5 or no
Yam Code
else not
is divisi le by 5.
m loer
ustem .ou println
by 5
a Divisible
525
I7 is divisible by 5