[YO Ue ee
GOES ¢E | %
le) ¢
SIKSHA ‘0’ ANUSANDHAN
DEEMED TO BE UNIVERSITY
Admission Batch: 2022 Session: 2022 - 23
Laboratory Record
Introduction to Computer Programming (CSE1001)
Submitted by
Name: CUNIRMAL SHAW
Registration No.:_224)019Y2#
Branch: CSE
Semester: __/St______ section: _22 W102
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Jagamohan Nagar, Jagamara, Bhubaneswar, Odisha - 751030INDEX
sl.
Name/ number of the
Page
Remarks and
No. | Assignment No. Se ae
A |Winle O Pron 7 Hate esing 1 14 ,
op [Mae a Comerele ove pmjism | > fol
halftone Pina ak
Ink A jova " .
3 Le inane pony ete) | 3
q [ane & saaT Pry m Tar” print )
iaf_name middle name, {act namel_Y
pink —& java Prager y
S| Mguet Some ow
6 | Programmiry: Adsynmeni- 2 [1-8 | | Lhe
He | Home Aasiynment 4-& a) G12 2
8+ | Progamming Assignmen)— 2 [IY - 2! por
gq. | Home Aamo Uaiag Kaylor |yp-05 9a- 1 2
(0+ |Using Command@ Line Agument |25- 27
| [Home ASsnment = Using Command . ho
u a “Tine | Argument [22721 ae
pomming Assignmen} ~~
1 [Peed Ce iNenal_statoments)| S27 45 ?
13. | Home Assignmen)- Us- 59] )
| Prgramming Aasgnment— 4
7 G anse SlelemabegP5- 65 \ fn
15. [Home Adsignment ( tterative stalmenl-) 65 - 44 | RB
16. |Prajommiry Assignment = 5 e
§ (Teotive Slolemends~ 2)|t0-83
qe RE ABN
(Alerotive Stolements ~ 289-88
8: 89-92)
Progannirg Assignment - 6ve
J5Y9I¢0-
2.
©
i
OS Aias
hCEES
€
we
6e
TTIIIE
= broyrmomminy = Asusnmen/-4
Department of Computer Science & Engineering a
Faculty of Engineering & Technology (ITER) CElemenis Of Prog rommizy)
Qt- Wile a Tova Pryrom to disrioy Following messayes «
Hello “ITERIAN"
Welcome to. Siksha: ‘0° Anusondhan, Fomiy.
Wecome lo “ Introduction to Computer, Labrotary
Java is -fun for Au tI
SOM Pybiic. class “Projroma i oe
pubic’ Stotic void main CString Os C1) j
Sysiem-out-Prntin (“Hello \“ TTERIANN' ”) 5
System «oud Printin (Welcome f° Siksha ‘0°
Anusondhon Fomity") ;
System. ow- printin (" Weicome to \" Introduction
to Computer losrotory\” ") ;
; System- ow: printin (" Java it fun for ANI oe
i
OvTPoT:-
Helo “ TTERIAN”
Welcome {0 Siksha
Weleome to “ Inivoduchon tO Computer loboratory
Java is fun for Ali I
‘
0’ Anusandhan Fomity .
ot
a
Nameduninmal
g
Outpude- "My name if Amit » Kumar deanng accoun} number
123956 having ‘balance #65998", 7
QF. Wile a java Progrom to exchange the values Of two
Variables Of inteper pe X and Y Using third tempor
yaraic Ze ¥ d J
Spin. Public Class Progromt i
public Stahe void main C Shing apps ty) §
1) Before Swarring
int x = 10, =
int Y = 20; a i
int 2&3
Syste oud: Printin C" Before Swopping the value of x ig: ex}!
sem: oul-pnatin C" & i ;
Sgslem p C" Before Starring the Value of Y is: “YS
Regd. Number- 22410] 972:43
: i f " a Ss
* epaitment of Computer Science & Engineering . ve Te Syst
Faculty of Engineering & Technology (ITER) Sor
\ : Te |g f
Cry
A Ale Swarring
Zed Gr
we
yr are
cae
ae wt .
Sysjem- oul Printin C Afier Swoppriy the volue af % FS + 42);
System Ouk- Prindin (After Swopriny TE volve oy "HINO
J Sry
J
lv
ouput: Before Swapping the value of % is : 10 o
Befare Swarrigy the Value ef yo is : 20 a
Adder Swoppi the valve xu ig + 20
After Sworrisy the yatee of y + 10
Q& bile a java Prapom to exchange the valuca of two
Vonables of iniger tyre X and Y wlinouk Using third
temporary Variables 6 .
Sei. Public. class prngrom 8 ; Sn
Public. Static void main CShing gs C3) 4
1 Betore Sworring
int x = 10;
ind ¥ = 20;
Syste out -Prindin C" Before Swopring the Volue of % iS 2" 4%):
Syslem- out: Prinltn (" Before Swarpiry tthe value of Y "td:
I After Swappiry
L= Ut;
Ve tev
VSX-Y;
Name: Regd. Number: 6Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
System Out prinlin CO Aller Swopriny the voue of y is: 43);
Output :- Before Swappriy the value of % fs = 10
Before Swarriry The varie oY Zo
Aier Sworpiny the ‘Value of xX is + 26
After Sw ari the value of Ys = JO
QF that do each of the “following Print 2
(2) System. out prinlin (5) ;
(b) System: out Prindin ( CHoa) 25/6) :
(C) Sydiem- Our Printin (5+ yr):
d) System - our Pron (5444 ays
(2) System: out- Prntin C924 g45)-
(1) System: out Pinttn (2+ "9"); ‘
Sap: - Public Class Propomd z
public Stake void main’ CString os LI) J
System. out. Prin}tn (5),
System: oud print in (Chat) 28 76):
Systm: ow pintin (5+ 6’):
System: out: Printin (54 Ft 69')}
System: ou Prinlin ("+ 445):
System. out: printin ( 2+ 9").
i _
os
ae Y-1666665
Name:————————_
ome Funnmal Shaw) Regd. Number 224101 992%
Slem- oul piniln (" After Swapping ine Vale Of % ig s" 4x):
J2
4
Department of Computer Science & Engineering e
Faculty of Engineering & Technology (ITER) ‘
Q10: Assume & String variable Yulerl ‘Containg “1” peg ¢
he Shing vuler) =)". Wrike @ sava Progrom to pin 7
Ye -fouowing Ovlput Osing String concalenakion - (You @b
faxe exha Stniy Variables) e
! €
124 — €
1213) 2 ‘ ‘ 4
P2132 YR@WM63h 2A de «
SOI public Class program 04 a
Public Stoic void main C Slog: ops CII S| g
Shing yuler} = "4"; 8
System. oud Printin Crwlert) 5°
System: Ou Printin Cyulert + "2" 4 ruler); %
Sgslemn- Ou printin Crvtert + 2% 4 vung 9% |B
Yulert + "ov 4 vulert ) ; S
System: ow Printin Crolert #2" + yer 3? 4
Yulert ¢ © 2" 4 vorert + “Y" + vytert 2 dN
yuler 3" + Yalerd + 2” 4 ruler) ;
a a oe DR APA M ADP
Regd. Number:
ae! H
ii
al ~ (Broan do cath of the oowing Prin’ 2
. printin C2 * “bo”;
« = (a) Lysiem- owt
jG: & (b) System. out Print tp (2434 (OD
> &) System. ou» Printin (Cae3a) + be"):
ik (a) este. ow rial» CBE” + (243).
— (2) System: Oud prntin (“bc" + 243);
TS | ule.
Soy | public class Prepoms 5
Sp Public Slatic Void main (Shing vps tue
yp System Ou « pintin (2+ “ bee
Ss» Syslem. oul Printin (2434 “ac;
td System. ow frintin ( C243) + «be") ;
oy iste. ou printIn C% be” + (243));
oy j System ub Prinkin (4 beh ae
vy [i :
Foe | litwt- 2b¢ \
=e 5 bc
ae 5 be
4 acs
ew, bc23
=v
SS [42> What do each of the “Potowirg frind 2
(a) fystem- out. prin ('6") ;
(by System Oud Printin (6H 4 e?);
eyefystem ou: Prinltn Clehar) Cas yy) +
3
PED
a
%.,
Solo. Public Class Program? 2
public Sialic void main (Shing ags CI) §
System. ow Prntin CBT:
System: Oud Printin C18 4 e?):
Syskm: out Printin ( Cchary ( ¢
DG de :
= ev).
Regd. Number:—22"
Jebel
742
_!
ddDepartment of Computer Science & Engineering
Faculty of Engineering & Technology (ITER) \
Ouyut:- bd
194
e i ‘ \ 4
Q3- Suprose that a voriatle a, is. declared af ink Q = MIB 360%
Cor equivalently, Iniger- Max. vate) «Whee do each’ af Ihe
~Fonowirg Print 2
@) Sysiem- out prinitn (a) ;
(b) Syshem- oub- fyintin Carl);
(€) System. Ow frintin (2-05
d) System. out Prinktn (-2-a);
(2) System. out. frinitn (2 a);
f ) System: out. Paintin (4#a);
Solr. Public Class Programs ;j
Public Stalic void main CString aps Gi) 7
int A= 219983697:
System: out: Priniin (a) 5
System: Ow Printin (atl);
stem: olu- Priniin (2-0);
Syskm- ol Printin C-2- a);
Spskm ow Pintin (2#@);
} System. out: Prinin (Y ¥@ ;
7. ’
Oludpub :- QIYHB3 6YF e
~ 214 7yea6yE
— 2199983695
2144983647
~2
alOro) POCO
TIGL L FF
6
JECT
«
EF
J
SER
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
able is declored AS dousle a= 314/57.)
Qy- Surrose Thal A von
Print?
Wal do each of the followi
(a) System. oud Printin (Gi
(b) sje out. print in (art);
te) System ow: pintin ( 8/ Gat) 4);
(ay poten out: Pindin ( 8/a);
le) sfyslem Old prniin (Cint) (8/a));
a. Pubic Class fropomy J
a cae Stabe Ud main (nrg os CI) f
dousle Q = 3-IW59,
Syskem- ow: Prinitn (a);
Systm: ow Puniin (atu;
System. Out piniin ( 8 / Cint) a);
Syskm: ow: println (8/a);
Sys: ou prinin (Cnt) C8/a))*,
§
4
ourpule- — 3> LMI SP ac
4-159
2
2+ 5Y6481203910124
7 ,
Jos. Wate a fova frgram to exchanpe the value Of Y vanigeles
w, GK, A Such that the value of W Will Move 10.
A.A t0K, Kt & and ~finayy Gi to W- Exchary wing
with ond without Usiry —exira — Varidbles «
Of. With using Exha vanables
Public Class Prgromsa
Public Slohic Void main CSniy args CI) f
inl W=1, 222, Ke3, gery,
Regd. Number,224101 QV 25
Name:er science & Engineering
Department of Comput
Faculty of Engineering & Technology (ITER)
: : —+ :
Grane oul Prindtn Ti Before Swarry oe +d:
« Before Swany qa fe? eal
y 1 th
diem. ou printtin C
Sys. oul Prin'dn (Before Swarricy K
System: OF pintin C “ Before Sworring d fe tg;
int lemp= 0;
Syskm owe pri
- pintin C“Afky Swope
S : 7 ry SWOPP) w rie v 5
an on ene Afkr Sworrigg O nt » ; Ne
Printin (" Afer Sworeirg Ke ise 2 + kK).
Syskm-
Syskm - Olu pri
}
3 printin ( Mkr Swdrrieg gis 4g:
J
Out
1S
before Swapping
Before — 10;
Number = Numer / 10;
int fourth - digit = Number ‘/o 10;
irl Sum— of digits = ( fist digit + Second — digit +
third — digit + foun ~ digit )
Syslem. ou pintin (" Te Sum of digits iss”
yj + Sum- of - dis):
fi ae
CML ee
e
Quid: Enter a number belween6 ond [000 : 497
The Sum of dyke iss 20
QS: Wiite a fovo Progam that reads the Yadivs of a hemisphere
and Computes the Surfore area and ‘volume Using the
Poliowing -formulos +
Surface Area Of Hemisphere = 3%1>. votume sf O hemisthere
= (2/3) AP, where is @ Consiont Whose volue is egual
sto 3-14 Oprroximolely « "y" is the Todius of the hemisphere.
Hints Use Math: fT
hol ©
Wi es
dt hw
oqepsestete
0.2 PIAS
Here is a Sample yun: i
Enter the radius of the hemisphere : 4-0
The Surface area of the’ hemisphere is Y6l> Bly
The volume area of the hemisphere iS Te. 343
Name-)
Name-unizmal .thawd~
Regd, Number 22 W042Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
(soln import fava. Ubi. SConner ;
Public class Prpamé f :
pubic Slohie void main CString oga C92 t
Stonner SC = new stonner (System in);
Syatem-owd- printtn ("Enter “the number of Seconds +"):
dovble Sec = Se nextDousse();
dovble dist. bovelied = (0/2) * 32-199 Sec * Sec;
Sjskm- ou printn C" divance travelled Wi be: .
$f + dist. trovened ) ;
j
Oulrut: Enter the number of Seconds: 5-4
Distonce troveried wit be 2 ¥69 09692
O71 Wile @ jova Progrom tnot disflaya the Potvowiry table -
Cast Frosting ~ point Numbers into iniyery «
a b Pow(a, b)
! 2 1
2 =} g
3 4 gl
4 aes 1024 ;
re 15625 ee
Sol import java. lil. Scanner ;
Public class Progamt f
public Static vord main (String orgs £1) F
( Slanner SCs New Scanner (Syukim-sn) *
,
NamedlUnicmal Shaw Regd. Number:-22W019Y24
2
—Y
eed
eo9P99 DO
2 HPO eS
aid
Ase dedddtddde
2.9.9. p.p on neh ES
GW OY VE Eye Cee
PP
ssDepartment of Computer Science & Engineering ~
Faculty of Engineering & Technology (ITER)
int a , b= 2, :
System: oub- pintin ("A NE b \E Pou Cab) a
Sgshin« out priotin Cae Myer eg be “VE + Cit)
Math. Pow (a,b) )
Q= atl, ’
b= bt;
System: ows prinlin (a+ Xt" # be “VL Cink)
Math- pow (a, b))
Q= atl;
= btl;
Systm. out printin (a+ "yee be WV * Cink)
Math - fow (0,5) )'
a= atl,
be bt),
Syskin. out frintin CO “\E™p Be “VE'e Cink)
} Math. Pow (a, 4));
d
Oulpub:
ee aan Zool G42
Regd. Number:
2]ee —
Home Assignment (Using Keyboord (rod ) =,
I
he
|
Department of Computer Science & Engineering S No
Faculty of Engineering & Technology (ITER) « »
(ar Write a jova Program “thal Promels the User ro a w
the minules (eg. billion), and distlaya “tne numaty ‘
Jes and dogs “Br ~the minutes « “a,
for Simplicily, assume a gear hes 365 dara. & Y
Hoe is @ Sample wn: @. °
Enter tne number of minules = 1000000000 e y
1000000000 minuies is Apfroximak}y 1902 yeora ond 217 dogs] @ v
Sol. Import Java. util Scanner » VU
Public Class HAOA F wy
Public Static void main CSuing ogy £3.) 5 oy
Scanner SC = new Sconner Cljstem in). 9) >
Syskm. oud: Printtn C Enter the numberof minut ea"); | y
inl daa = 19905 1.1 day = 110 minuka $1 2
Int jeart = 525600; [J 1 yeor = 525600 minures 2] 3
ink min = Se next Int 0); el 4
int year = min | years ; ry
ear S 3
imt adage = Cmin=Cgeors # geur)) / days ; q ¥
ystam- out Printin (min + “min is depeoximalely” 3
G m7 tay + te Gere and” + days + & days") $5
j el 3
Enter ine numb of minutes Lo we.
3
100000000° 7
[000000000 minutea is Aprrovimalely 1902 yeora and 2Y dara. ek
22 oSDepartment of Computer Science & Engineering °
Faculty of Engineering & Technology (ITER)
Q2- 1 gou Rave N eggs, then you have Niin dozen ec,
With N ‘Jo 12 eggs tefl over. Cthis is essenialy the
«+ *, - = | 7
a yava projrom thal asks the user how mon “yg
She hos and then leis The user how mony dozen aS
She has and how mony extia eps Me left over. A
Jims of Oys i Qua to. 14y fs - Extend our Proprom
So that if will (eu the Wer how many Gross, how
mony dozen, and how mony Jel} Over sya She has. for
Fxomele, 1{ the User Say that She hoa 1342 Gps, and
then qour pryrom would respond with Your number of
Gio tt es and 0.
re
SF [pe lint fora. Ultk fconner ;
e public Class HAQ2 F
Public Slahc void main C sinng args cid
Seonner Lo = Neo Seonner (Sykm: in);
eLyster out. printin (" Enler the total number of “js
dou hove ");
int ag 7 See next TInt;
inl Jims = IY
int dozon= [21
int’ gr = Qg / press:
int dz = os
: Cy (gress *q) / dozen -
ink [eff = (egg ‘/ Jwss) ~ dozen » dz
System: ou finn a Yet ander oF Yd is "4 gre
4 o qtss N+ dza™ dozon and” + left )
3
—Sluninmal fhaw
Name: Regd. Number:22UL0/442Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Huk:- enter ihe ola! number of eggs fou hove
ul
1342
your numaer of ype are 7 Juss , 3 dozen and 10
Q3- Wile a jove Propom thal Prompls the User fo enjer
three points (a yt), C22, 2), C28, ¥3) Of a bangle and
disploya its area The formula for Computing the area of
a tranple is
$= (Sidel + Sider + sides) | 25 :
avea=y 6 *CS-a) ¥ (5-3) ¥# (5-C)
Hue Ws & Sompte run:
Enter three points for @ triongle + 5-34
U6 5 95 -34
The V4 Of the tone i :
yle is 33-6 -
Sof- import sova- Util. Sconner;
public Class HAQS 5
public SloHc ‘Void = main C shiny ous ty) J
Sconner Se = Mew Scanner Chystem. in) ;
Syskm. OUE- Frinkin (Enter three points")
floot %1 = Sc» next Float; °
sfivat Yo = Se> Next Floall);
Finck Xa = SC next Float 0;
PH 49092 DI98n aa
Atoat Ya = Se next Float); 4
fiat Vy = Se NextFlotO; Yo
Foot Ys > Jt. NextFloat 0;
=e =23,2}+(t4-9),2))%
Lig —didea—=-Mattr Sort Me ¢
«
fa ~Suninmal Chow)
rae : we ES
aDopartmont of Computor Sclonce & Enginooring oa
Faculty of Enginooring & Tochnology (ITER)
grt (Mam. ALS (alt row ((2-¥1),2) (1
}ool Side2 = Mon tC Mom-nbs (Mat Pow (04-2) y+ (y
oct Side = ram. syrt (tod. abs (144m row ( (aye x ,
flool So =
fioo (Sider + Sider + Side 3) / 2-085
‘flool aio = Math. Spl (Main. are Us ¥ Cs Side ¥ C5~ 51402) 9
Cs- srdes))) ;
“nol ("Me area of Mongle is" 4 area);
OUI Enler three points: LS i-3-y yg 5 95-34
The Orea of he (mangle 1-33-6,
USing Command - line Argument
Ql. brite a fova Prom thal Joker two int vatuea from
the Commond line aa dividend Qnd divisor and print
Me Yuoheni and remainder.
Sol Public class Q4
ayy;
07) (Ult-ya) 2);
Public SIGHe void main Csiny Cy aps)
int dividend = Thi ger: farseInt Cogs Cor);
int divtsior = Tnleyer. porseTnt Coys C43);
Int’ Quotient = dividend / divisor:
int Remoinder dividend Jo divtsyoy
System. out: Printin (" The dividend is: ? yp dividend )
Systm Out Printn C" The divisor is: ” rm draranye
Sgakm- Out: Printn C" Te Quonent iss” » Ovshien} ) a
q Syskm- oUF. PrinlM C The Yemaind er + Remainde)
4) 01942 F
Nam Regd. Number:
25Department of Computer Science & Engineering e
Faculty of Engineering & Technology (ITER) ~The
Javac &4-jova
fova Qt 28 6 b
The dividend is = 28 eS Nb
The divisor is * 6 eo
N
The Quokent Is: Y
The yemoindr i 2 y i
Q2- Write a jova Program hot faker f0 Positive integers
from Command-line arguments and prinis Ae vesut as
fins} Number raise to The Power af sSeond number - pa v
JStle:- Public clase Q2 el '
Public Stake void main ( Sting LJoys) f e! ‘
int Q = Inlgyer. parse Int (ays tot);
int b= Inigyer Parse Tnt Cages in)
int Cc = Cint) Math. fow (a,b);
System. oud. printin (a+ "to the fower’s ba “iss "4 ec).
3 x
J
Ouiput:- fovac Q2- jova
fovaQg2 2 4
2 to tre Power of 3 ik t &
QS: Write a jova Progrom that frints the cum o& two random
integers between J and 6 CSuch ad Jou myn get when
rolling dice)-
Sale Public Class Q% 5
public Stake void main (Shing ape C3) §
cee
Name: Regd. Number: OITRESPeEeMmumauvuweewrwvee
me
a oe
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
int mox = Tnlyer- parse Ink (args COI)
int mi Tk ger Porse Tnt Corgs CI);
ink vandomt = Cint) (Math. rondom ©) * Cmax -min) + min);
Cint) (Main. yandom() * (mox -min) + miny ;
0
int rondorn2
ink yeruit = YOndom) + Fandom 2;
System: Out. frinktn (The Fist random numser 16 =" + tondom) );
Cy skim. out - Prinkin C The second random number iss" + pondom2);
[System « Oud Printin C* The Sum at two random imgyers between
4 and 6 is: ” + result); :
Oulrwe: Jova a3 jova
jova &§8 3 4 ,
The first random number iS - 3
The Second Yand6m number io? 5
The Surn 6{ two render integers between | and 6 15 3
OY. Winte a Jove Progrom that Takeo a double volue t from
the Command line and frints the ‘value of cos (St) +
Sin (4). Use Math-cos() and moth- Sin C)
dis Public Class Qu §
Public Stabic void mein CString ays tI) z
double t = Double- fase Double Cogs Cor):
dovble 6) = Math. toRadian s(t) ;
double resultt = Matn—cos (5 * 4);
double vesulla-<—Main - Sin (4 #t4)5
double recut = rvesu/l4 + resulta >
System out: Priatin (“ The Sum 6f Cos (St) and Sin (st) is 2”
j + result) 5
u ma tinted Glas
Name: Regd. Number22¥/ 0) ¢u23
2tDepartment of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Quiput- jova QY- jova
Jova &Y 40
The value of Cos (st) and SiM(7) TS 2 ~ 099999999999 99797
QS Write a java Progrom ‘that teked three int Voluea from
rthe Command line and Prints “them in ascending Order.
vse Math. min() ond Math.maxt).
Mole. Public class QS §
Public Staic void main (String Clays) F
ink Q= Antger «Parse Int Cars COI) ;
int b = Intyer- farseInt Cargs CI);
Int C= Fntger- Powe Int Cags 23);
int m1 = Math. max(a,b);
int mox—value = Moth-miox (m4), c) ;
int m2 = Math-min (a,b) +
int min_ value Matn- min (m2. ¢c);
int mid—-vaue = atb+ C-(mox—value + min— value):
Qystem. ow Pantin (6 The numbers in Aseinding order iss
aon
Min- value + “ 4 mid -value + + max— valve) 5
Output :- fovac Q5- jova
gova QS Y 20 &
The numbers 10 Mecendicg order: Y @ 26
nN
Name Soniemal thaws Regd. Number 201d =F _—Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Q6. Wile a fova prjom to input o Charo her from Command
line and —disploy the Ascll value of the entered Choracke)
Gale. Public class QS F
Public Slavic Void main Costing Cj ays) Z
Chor a = args CO]+ chor ALCO);
Syskm. Oub- Prin it (tint) a) ; oR
J / * Choy C= os te] -chagt co:
J im b= Cc; :
. : System. oub- pint (b). of
dulpur fovac A6- jovea a aye
Jova Q6 A
q4
At lavite a jova Praprom that takes three Positive ingens fom
Command ~line Oiguments and frinis tue if ony one ot them
is less thon or @qual to tne Produit of the “Other Hod and
aise Otherwise
So. Public class OF F
Public Static void main CString CI oy s J 5
int a= Integer. forse Int Cas Cor) 5
int b = Imiger-porseInt Cargs CI);
int ¢ = Thiger- farse nt Cogs Eaay
"
boolean d = Car= Coed) Il b <= Cowes II Ce <= (aes):
td dd oP aD PTH EPSP ED BP? DP
RegiNumber LUE yfBepartmant ar ompULAY Aelwnee & Enginesrng
Faculty of Engineering & Technology (ITER) ;
Ho}. Public Class HACLAPryram2 F )
Public S16hic vord Main (fining ays (I) 2
double y = Double - fawe Double (ays [0J),
double h = Double. parse Double Coys Cia);
double Surfore_ Area = (Cran er 9 Math pow (1,23).
+ (24 Main-er vy #h))
Syskem. ow teint an C The Radius tes" 4 x + Gnd the heignt is:”
tht “So, the Surface area of Cylinder i: "+ Surface - Awa)-|
3
j
Dudpuk:- JOvac HACLA projrom 2 -jova
ova HACLAfagoma 4 9
7 and the hejpht » 9, So, the
The Rodivs is :
Surfore ova of Cylinder is + 5y9. 7483193782139
QS Write & Gtva Program to Ingut a four-digit number from
Command line Grfument and find Sum ot the first and
last digit of ne number.
Bol Public Class HACLAFrogy om 3 4
Public. Slavic void main (Sing oye C4) §
int N= Thteger.parseTnt Coys Coq) :
int firskono = N / tooo:
int [ost- no = n 7 10;
int Sum = firshono + last_ono :
Systern. ouk= Pantin (* Your four-digit number is
«“and tne Sum of ‘the first and lou digit of the number
»
tn +
ig" + Sum))
jovac falifgas
$output:
3 ea! Jove Haclarnpsms 9709
Your four dipid number 8 29709 ond the Aum
firs! ond Gai _dyit the number ies Le
Suniumat Thaw Regd, Number,-22¥/0/ 202 # _
m,
Name:9
SC eonditional Stalemen)s.)
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Ze
Oe E
Ql Write a Progrom to ingut the age Gl QA Person and Check
if tne age of “ne Prion if Qreater Thon or Cgual po 18
‘then punk The message + * You ave eligibre to Cast goun vote”
(Soll:
import fova- util. Scanner 5
Public Class Program) §
Public Static void main CString orgs C1) §
Sconney SC = new Sconner (System. in);
System. our Printtn (“Enter youn yes "D5
int Qe = Sc netIntO 5
it (qe>= ts) ft
Sysiem. wks prinitn Ch you are eligisie FO Cos) Your
} note");
PH9NDD OD
WCE HHH EOE
] ef
Oultuk:- U) Enter youn ae + 20
You are eligible to Cast goun vote .
(ity Enter youn Ye * +
Q2. Alice visiled SUM hospital to get tresiment -for her Giae
Gnd iltness+ Doctor Advised her +0 drink ai [tast 5600 mi
Gh woler each doy. Alice dronk % mL oF water ‘rodey .
lnte Q Prgrem “thar print “the” “Fontowi ng meisge
depending on the value of %X-
soln,
import laa a
Pubtic Class Program
Pubic Static void main (sting ays tf
Sconner SC= Mew Sconnes (dyskem -in)-
Nemo Sunimal Shai —
Stonner;
OU YW Wureda
XN
3
wue
Regd. Number:-22¥10) 4424 el
aDepartment of Computer Si
2 cle
Panay of Baginoorhag & ochnology CHER
a
Tosi soup boot ("Ener The Omovnl OF wala opm
int woler = Sc- nexLTrt O;
if (woler >= 5000) $
System. out print to (Yes, alice is fovourng doctor's
j Odwite *
else i
System: ou Prinkin
J
(No, Alite i not fonnowry dottre,
aduce");
3 f
Oulpub s= (1) Enter “Ihe omeunt of waler in ME 6200
yer, plite is Following doctor's advice.
in mt 3450
Ui) Enter ‘The ornount st woley
doctor's advice «
No, Alice is MO fouowing
3. Lavite a Pragrom ‘that reads Hhyee inlgers Avorn the User
land prints“ {nereasin vif the numbens ane fn an inqeasin
order, % Decreasing * FE the numbers one in descending Order,
and ‘* Neither increosing nor decreasing order” ofwrwise -
Here is the Somple Un:
© Input First number = 201 ® Input first numbers 4s
Inpur Second numbr > 345 Input Second number: IY
Input third number > U5 63 Unpur third Number > 3
& Inureasing 7 « Derwosiry ”
© Inrut fist numbers 395 —
Input Second rune Ts
Input third nunider s 56%
& theither Increasing OF decnsig’
Name-Sunismal Shaw
Regd. Number: 22410) 42ESole.-
j
import jova- ulil- Sconney +
Public Class Prgrom3 §
Oukpuks. Gi) Enter first number: 5 Wii) Enfer firs) number : 45
i) Ener fist number +345
Neiiner Increasing nor decreasing «
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Public SJolic Void mein (Shing orgs ta) &
SConner SC = new SConner Coystem in)
fepstem - out Printin (" Enter first number : ");
int Q = Sc nextInt O;
System. oub- printin (“ Enter Second number =") +
int b= Se nextIntO;
System. ows Prindin (Enter third number >");
int C = Se nextInt );
HU (aceb tt bxXec)
Sysken- ouk- print ( Increasing") ;
al
owe if (Ar=b 44 br=c) Ze
} System: out: Printin (« Devreosing ").
ese
System. Oub> printin C" Neither men Nor
} deeeorig®
a
Enter Second -number 2 7 Enver Second Numbers MY
Enter tried number 220, Enter hid Numba 2 3
Increosigy ‘Decreasing
Enter Second Number? INS
Enver third Number > 563
Rath, Numi|
FH SE
Py
GAPE
qearrnangnend F
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
QY- Moke a Simple game invowing a Compuler ond @ User.
a
The Compultr fist g Mester number between | and @F
inclusive , then @sK The User to enler Q Number between |
and °9 inclusive’, Hf the User gueda rs Correct then displa
ye pe a, tO gee close Cer, =I)“ Almost:
get it”) Otherwise «You Jot He wrong oe
Here ave Some Sample Yuns -
Enter user number : 2 Enier user numser : 4
Computer gusses 2 3 comruier gusses 2 4
" Atmost got it” « You got re right"
Enter User number :
Compuitr gusses : 5
* You got it wrong”
Sol
import Jova. vtil- Sconner 5
Public Class Prgomd &
public Starve void main (String CI gs ) 3
Seanner SC = New Scanner Cystern- in) 5
System: out. Prin| tn (Enter a number between 1-9: oe
int Userguess = Se- Next Tak Oo;
int Compguess = Lint) (Math. random () * Cq-14+ +1);
System. out. Print in (user guesses i "+ Userguess ) ;
System. out frintin C% Computer guesses =" + comguess )3
if Cuserguess == compques.s ) $ .
System. ous frintin (# you gok it right")
ese if (mat. obs Cosergu £5 — Com
g pyuess e= 1) ;
Syokm. ouks Println ( Almo "
pate th coat
; Syplem-ou-¢aanin (" You Jor it wary"):
Regd. Number:
w
aDepartment of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Outod >- Corte ute tune ben:
@ Enter a umber in between 1-7
© Enter a number in baween 1-9 &
5 Computer guessed the number
Computer guessed the number Your guess is % ]e
I
Your guess te 5 Almost gol it a! te
“You Jot in Ureny re
e!
re
&5. Write a jova Propiom thar fakes a {tar From user Gnd rind &
bue if tat “yeor is a leap year Otherwise print falre-
Here is @ Sample yun:
Input the geor : 2016
Inruk tne gears 2008
2olb is A leap yeor: te
26 is a leap year: foise
Input the geor > (oD
196 is @ leap Year> forse.
Salt =-
import jova - utile Sconner ;
Public Closs frogroms z
pubic Static void main CString CI aged §
Sconner SC = New Stonner CSystem-iny +
System: oak. Print (“Inrut the gear 2") >
int Year = Sc- nextTnt dd,
if (Yeor %/o4 oye
Hf Cyeor Ys Io
if Cyeor te YR ==
net
BAY
3249
$3)
=
WE DOO
in (Year + “isa teap gears
tue ");
else he
Syskm oud: finkln (Years +" is Pot a leap
J geor : fane ");
apeegtws&
Regd. Number 20017
4SIV
dd
tt dd
a? RP
¢s
lid dai
t
dbbdIILHUTTS
i %
d
Repnrtmant nf Computer Beienee & Rnaineering
Paluliy of Enginooring & Technology (TER)
else
Syshern- oud Prindtn (veer + “is a leap yeor : tue "
JS
Jest z
Spstern- outs Printin (year + “is pol a leap yeor : false
j i
Qubtut: Inpub Ine yeor s 2024
2024 is A leap yeors true
Inpuk the years 2019
2019 is not a leap ytor fae
G6. brite G jova frgiom fo Colculale the rmomthyy electaici Ly
bi. The tovidt fs given as cfonows :
Price Per UniL [unit vonge
RS. 3/- First 50 units
RS. 4-80/- 50-20 unils
Rs. 5.80/- 20-woo units
RS. 6-26/- Above Yoo units
Solo
import fova- util. Sconner ;
Public Class Progrom 6 2
Public Static void main Cstnng CI ays ) 3d
Sconner SC = New Scanner (System-in) ;
System: owt. print CS Enter youn Power Consumption anit :}f
int unit = Se- next Tn 0;
double Bill = 0-, 7
H Cunit <= 50) $ :
Bill = unit 32
System: uke Printin ("You hove to fay Re." Bin)-
J
Regd. Number:—224101942+Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
( else if Cunit <=200) §
Bill = (50 *2) + (Unit - 50) % 4-40;
System. out- tintin (“You hove to Pay Rs. "+ Bi) )-
ese if Conit <= yoo) t
Bin = C50 * 3) + (150 9 4.8) + (unit- 250) 5-60;
System . OW Paintin (You hove +o fay es. "+ Bin)
else
Bin = (50 #3) + (150 #48) + C250 % 5-50) + Cunil~ Yom) 6-2,
; System. out- Printly (" You hove to foy RB.” + Bill )>
:
3 i o 4
Outed > Ente, foU7 Power Consumphon Unit‘: 200
You have to Poy Re» 840.0
QF: From ine above queslion no-(6) wrile a jove Progrom with
Q Choice MH the Consumer Wants 4 Par bin online .
Consumer Who fogs “the elecincity Sill online wil) gu a
discount of 3-/.
Here is the Sample run:
No- sf Units Consumed > &64
Ddo gow wont to fay Online Ory s
Toto! Qmount : yq25-¥
Discounts (YF - 462
Amount Pogoble = W777. 638
< :
Neme:—funiumal thou) — Regd. Number24W10) 97
3e
Umea me ee ow ov 28eaah A» Aa an.if if
f
COMA / 6 J
Ss
i neering
Department of Computer Science & Engi
Petty AP BHUIHReNHTA RHI NRINGD! CPD
SoH
import jova. util. Scones;
Public Class Progrom 4 j
public slaiic void moin (String C3 Og) Z
Scanner ge = new Scanner (System. in):
System. out: printin (“Enter gour Power Conumpbian Unit J
int unit = SC+ Next Int;
double Bil = 0;
Hf Cunt <= 50) f
Bill = unit ¥ 3;
System. oud: prinitn ("You have to Per Ro.” » Bin) J
else i (unit <= 200) $
Bil = (50% 3) + (Unit ~ 50) * Y- 80;
System. out Prin} tn (You hove to fay RS-" + Bin);
ewe Hf (unit <=40) i
Bil = (50¥3) + (150 # 4-8) + (unit- 200) ¥ 5-80;
} System: ows Printtn (“You hove to fay Ri" Bil):
ele i
Bill = (50¥3)4 (150 ¥y.8) + (200 8 5.90) +
Cunit- Yoo) % $-29:
: a » :
System. out Prnlin ("You hove to Poy RO" + Bill),
System out Print ("Do you wont tp fay online (¥/n)") ;
Char choice = Se. next). charAb(o) ;
Switth (choice)
Name:-Supiumal Shou
Regd. Number:—22¥1019 42:Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
OO
Case SY? : 1
double discount = Bill * 3/100 ;
double New- Bill = Bill ~ discount ;
System ouk- prinlin ("Your ‘discount is R=" discount);
System - Ob prin tin (" You hove to fay” + New Bill);
break;
Case Sn? = ;
System. our: printin (" You hove to Pay Ro” 4 Bill)
$ ,
3 J WA (
Outre: Enter ovr Power ConsumpHion unit: 325
You hove +o Poy Re» 1595-0
Do you went to Pay Onling (YIN):
(
Your Discount is as. Y4-8s
You hove to Pay IS YR. 15
© Enie GOUr Power Contumpion units 325
You: have to Pay RS 1595-0
Do you wont to Pay Online On): n
You have to pay 1595-0
Name Show) Regd. Number;—22) 2
uOcering
> Department of Computer Science &E
Faculty of Engineering & Technology (ITER)
Propiom that Jake 4 the 4-7 Coordincles of @
and frais & Message elling
point tes Or the Yuadant in
Q8- Wrile a jova
foint in ‘the Carlesren [lane
Either on axis on which the
which it is -found -
Here is the Sample Ollput-
(-l-0, 2-5) fs in Quadront TL
(0-0, We) Bon the Y-axis
Solo
import {Ova - util - Scanner ;
Public Class program & 3
Public Satie ved main (Sting CJ args) i
Stonner Se = new Scanner Chyshm - in);
System: ouk- Printin ("Enter x and Y¥ Component of the pont’);
double % = Je. nextDoubleC) ;
double Y = Sc- nevtEDousle 0;
if (xy0 44 Yoo) F
System. uk Printin (a+
ese iH (x 0) f
System. ow: printin (RF "4 ¥4 “is in Quedvent a),
5
aue H (2<0 4h ¥<0) f
fystem- out Printin (2X 4S" 4 Ya" is in queedront TL’)
- i (x0 44 <0) i
Systm: Ou frinuin (24 "4s" 4 Ye" in Quedront Be");
“
"> Ya Vs in Quadront I”):
Un).
Name--SS¥niumal Shad. Reed. Number: 1OT9YZE
GOCPCSCCOCCCRYRCSESEHCECOGOEEEEYM EG Oe ***
YtDepartment of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
awe if Cz== 0 44 ¥!=0) 2
System Oud print in (De Ge ye Mis OM the Hanis” J;
5
ae iH (Y==0 44 iso) 9
Syshm: ow printin (2 + "4 Vt “is on the y- ais"),
ee HC 2zs20 £4 Yor o) §
System out-printin (24 "4 Ye “Fs on Me onyin ")
jOurput: Enter % and Y Component Of ihe paints 2 5
2-0, 5:0 is Dan
QI Weile Q prgom to Intub 3° inleger number Q, bc. Find me
largest number Amony 3- Alo find ‘the 2nd layeak humber
mony 3. Were ke the Sample Outpuk:
Eoler the value of 4,4, C: 10 20 50
Congest number + 50
and Largest Number 2 20
import java~ util Scanner;
fusiic Class fiagrem 9 §
public Static veid min CString Cl Ge
Sconner SC = new Stoner’ (dyslem-in) ;
Syste owe frit ( Ener! three numbens ="
Name Suniemal Rega, Number. 22MLOLT424—
urDepartment of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
ink a = Se. neck Into;
int be Se Next TntQ:
jnt ¢ = SC NGLTALL) |
if (ar=b #4 b>=c) §
Szslem: Oul- Printtn (a+ “is the [axpeat number”) «
t ae if ( bd==c 4£ Bk=a I b>=9 44 beac) §
System. owl printin (b + “is the Ind Moxgeat number} «
else }
System oud. prnein ( C+ “is the 2nd Jai u rr").
sy C geak Number J
34 Us
3 oe
OWtuL > Enter three numbers > 9 By
9 is the largest Number «
7 Wothe 2nd long «a4 Number.
Name: Regd. Number:—2 1019.4 2-7
43Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Q10- A Univesity Conducts a 100- Mork exam -for its Student
and grades them as follows» Assyjns 2 quade based ON
the volue of the morts. Wile a jova fryrom to pant the
Grade Occerding to the mark Stewed 4 the Stodent ~
[uses Switch cose J -
Mork, Range [ Lelir
Wied O
Y=8O Ann <90
y=% awe <80
y=60 AND =50 AND <1
240
ai ml] Oo] | >) e
Soft
import fova. Uti) - Scanner ;
Public Class Progromio 2
fublic SHakie void main (sting CI orgs) Z
Geanner Se= new Sconner (System.in);
System oul- printin ( Enter our Monks + ae
int marks = Sc- next TatO;
int Ro = marks/ 10;
suinth (1) §
Cose 10: , _|
Case 9: System - ou polin ( Your rode is 0 .
7
buak:,
Cow § 2 Sytem. out: Prinkin (8 Your grode is a");
breok
wame- Con Regd Nimber= 22NLOLV 2 —
M6FT
97 7.979 FSU
=
GAIA SG
HARARE
i
FHEDITEE.
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
if C computer = = user) 5
fps - Ou Print tn COM is draw");
ewe §
boolean win = (user = =0 ££ Compokr = = z) ih
(user== | 44° Compulr == o) Il
(user = =2 44° Comrulr= = oe
if (win) $
System ou prion C% You won");
ese F
Szskem ou) prinjan (You lose")
J
i
J
s
Ourput:- (D Scissor (0), vocK C1), Parr (2d: I
The Comruter is Scissor
You are TOCh-
You won.
@ Scissor (0) , vOLK C1), POPE (2) 2 2
The Compukr is POPer-
You ove for ro
1k is a draw °
Q2- Write OQ fovea Progrem that from
intyer for or s oi oh vis the Wer f enter an
: t a eWeek ( Sunday i 0. Mond
is J. ond soturdg i 6). Alo ft 2 a:
rome} the User td nk
the number Of Adaya After “fodoy for & fulune da ne
: < an
disfloy the future day Of the week. d
Name:- n
i Regd. Number: 01242 F
47Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Here is Q Somple yun:
® Enter todoy's doy: 4
Ener the Vinten of dogs Clarsed Since Todor : 3
Today is Mon doy and the future aay is Thridog -
® Enter today's day > 0
Enter jne number of dogs Clagsed Since today: 3
Thday is Sundyy and he foiwe doy is ednesday «
Sif,
import java. Uti}. Seanners
Public Class HAPmyram2 i
Public Static Void main C Sting tars) é
int doy , dag , Aday
Sconner oe = new Scanner (Systm in):
Sysier. ouk- printin(. Enter Today's day : ");
doy = sc.nedInt 0
System. ow printin C® Enter the number of days elapsed
Since ‘today : a
Uday = Sc- nextILO;
if Uday = = 0) t
System: oud: print ( Today is Sundey ond”):
Fewe if (day == 1) £
System. oud Print ("Todgy is Monday ana”)
eit (dy == 2)
Jes iv co A (Today is Tuesdoy andt *)y
if (day == 3 3
j wt - oa (Today is Wednesday and”)
224)?
Jean. Duk Print « Today ig Thursday and"):
i
Regd. Number:—22410/2924
Yeell
ell®
ot?
ig 10 clivisile by 5 or ¢, but not both 7 True
ety 7
et [oe a4
ols imtort java- util. Sco
a "| purtic class HArmgomy f
) puic Sabie void main (Sting C1 args) i
Scorer SC = New SConner (System in );
Name--SUuniamal—sShaud—- Regd. Number:—2241 01
5}Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
System. ow pint (Enter an Intgper ¢
Int No = Sc- Next Int ©: »
System. Ouk- Print tn (Is"4 no +" divisible Yy 5 and 6 2
+ (tne #5 == 0) 44 (n0%5-=0)));
»):
stem out: prinltn (“154 no + “divisible by Bor 62"
+ ((n% 5 ==0) I (no 7 6 ==0)));
Syslem: out Printin ("15 4 no 4 “divisine by 5 or 6, but not Jon 2”
+ (tno 5 ==0) A no th ==0));
Gi
J
Oukput : Enter an integer = 10
IS 10 divisible by 5 and & ? false
1S 10 divisible by 5S or 6% tue
Is 10 divisible by 5 or 6 , but not both? True
QS. lAite @ jovo Progrom which disrloys Gn arrropriale name
for a Person , Using & Combination 6 nesied ifs and
Compound Condikms. ASK the wer -for a gender, first home,
Jast name and aye. If the Person is femote and 20 or over,
sk if She is marieds H So, disetay “ Mrs.” in front Ot ber
name. H not, distlay “Ms.” iD front of her names MH tne
fernate is Under 20, display her cfivst ond last Nome. If the
ferson Wy mak and 20 over, disploy £ My.” in front of his nome »
Otherwise , distlay his -fint and WA nome - Note that Asking a
person if they are momied Should ony be done H Iheg are
ftemole ond 20 or older, Which means ou. will Rove Q Single #
ond else nesied “inside one H gour H Slolemenis. Also, did fou
now that With on if Statements Cor ele), the Curly braces are
Name sumuimal Show) __ Regd. Nuinber; 22410194 24
5DQe —<—_ = ——etF
cience & Engineering
uter S
, Department of Comp' Ce TER)
Faculty of Engineering & Tec!
one 4alemen} tnside ?
Optional when there is Only
Lamele_ wun:
What is gour gender CM oF): F
First nome : Gita
last nome : fatkonoqok
Ale 1 32
Are you married , Sita Cy rn)? 7
Then t Sho you Mrs. Gita faltonayak
Solr.
import Java. util. Sconner ;
Public class HAropom s 4
Public Satie void mein (sting CL ays) Z
Sconner SC = new Scammer (Qslem sin):
System. oub-Prinklol" wlhat is qour gender (mor F) :")'
Char Gender = Sc-nextline C). chor at (0):
Systems owe. prinitn (Fist nome +"):
String nome = Sc-Nextline ¢);
Lystem ow Printin ("Lost nome + "J;
Sbigg lasinome = Sc-nextline O 5
System -ouk- Printtn (“Ages”);
int Ye = Sc-nextTAtO,
if (gender Cm? J) gender == 6M’ 44 age >= 20) 5
System. out: prinkin ("Then 1 Shan cau gow +
name ®."):
J cue if (gender =
System-oub-Printin (Then ¢ Shalt calt gou” + nome +
w+ Lasinome + &.¥)>
System. out: frin}in (« Are. ou mortied E + name +
“CYorn)7"):
Stninmal Show —_ Regd. Numher:—22 IDA 2
Name:
tor Tl gtr == €04" dd oye < 20) §
4 else if (gender =< 4° IT gender = =F? 44 Gye > = 20) 3Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Char moved = Sc- next ¢)- Chor At C0):
if Cmaried = = Cy" I] maried eety’) 9
System. out. frinttn (" Then 1 Shon Can Fou ms "4 name 4
> & ostnome + "D5
Jewe §
Sask. out printin (Then 1 Shay Catt gow Ms.” +
nome +.) 5
Seve §
Sgplems out frintin ("Then 1 Shait cal gee” + Dame. +
te? + lastname + “-* ):
Oulfuks® Whot iS your Sender CM or FF): M
First nome + Somneth
Losi Name - Shaw
Age: (9
Then 1 Shot) Coll Jou Somnath Shaw -
@ Wal (© your gender Cm or fF): M
First nome : Sunirmal
Lost nome: Shaw
e iat 9
Then 1 Shall Col gow par. Sunismal +
® Wa is your ender CM or FD? F
First nome = Angali
Last Nome: Banerjee
Age 2 48
Are gow monied , Anjali Cy on)yz2 ¥
Then 1 Shan Co fou MIS. Avgli Bone gee :
Regd. Number:—22MI 019424
ayDepartment of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Pag jromming Assignment = I
(Tteslive Stalemenis- 1)
Sesser eae
QU bvile a jova program tral gets three inleper Numbers fom the
User. Count from the first Number ‘fo The Second number incrementy
by Ane Thied number, Use for lor to dd ik. Also, distlay the Sum of
Turnbers displayed between -the first number and Second Numser -
Sample yun s
Enter first number:
Ent Second number? 13
Entey third Number: 3
Yo 4 lo B
The Sur of number disrlyed 1S 34°
Sole,
import jova- Util Sconney;
Public Class Program) 3
Public Stobic void main CStany CI orgs ) 3
int Sum = 0;
Sconntr SC = New Sconner CSystem -in) +
Syslem. ow. Printin ("Enter 18+ Number iY:
int a = Sc NexETINLO;
System. owl Printin (“Enter 2nd Number: ")
int b= Se nextInlO:
System. ows prntin (“Enter ard numbers"):
int C = SC Next MO ;
for Cint i= 05 UXeds (re) F
= Syslerm. oud Print (i+*");
a Sum = Sum +t:
System out- pranitn (“\o The Sum ef Number distlaged fs 2”
4 + sum);
Name: Reed. Number:-22WOlPY2 7
osDepartment of Computer Science & Engineering
Faculty of Enginecring & Technology (ITER)
Output: Enter Ist Number = 4
Enter 2nd number : 13
Enter 3yd number : 3
Yo4 lo B
The Sum of Mumder dispaed to: 34
Q2: An inkger n is diviciate by 9 if the
divisible by Y- Use this Concept in
Whether oy Not he
Sum of ils digits is
our Projrom fo deltrmine
Number is divisibye by 4. Test it on “the
Fottowiyy Mumbos : Use while toop-
2
"
(23456
ISY36E
N= 621594
=
Hint + Use the */. ofuotor to get each digit tnen we f opearw
to yemove The ign .
Sole
tmport jova- Util. Scanner:
Public Class prapoma2 5
Public Static void “mnain CString ays C3) 5
int num, ln, ¥, Sum= 0+
Sconner sc = new Scanner (System in)
System. oud frinkin (Ener a number : *)-
Num = Sc: NextInt ); ;
tn = num
while (num! = 0) z
y= Num “> 10"
Sum = Sum aie
num = num / 10° /
te,
/
if (Sum %9==0) 2 iy
System Ou- Printin C® The number + tn + “ ig
divisible by q")'
i :22Y/01902%
Name:-voiumal Shaw. Regd. Number: 56Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)
Jase} 3 i
System: ow: prioitn ("ome number" In + "Ts nok divisine
by 9");
Outs. O Enter A number: 1SV36E
The number 159368 bs divisible by 9.
@ Ente number + 123456
sme numba 123456 is Not divisibie by Ge
m that fakes an integer N from User,
Qs. Write @ Java Progra
EN random iniger num bers
Uses Maths Random ¢) TO FHP
betwen 1 to N, and then
tohile Looe -
Sor.
import ova» ub. Sconner;
Puslic Class progriom 3
Public Static Void Main Costing CI ags) J
f=l;
rinks heir Qverage value - use do
ink num, 1, Sum= 0
Sconner SC = new Sconner CSystem + in):
double ag: