0% found this document useful (0 votes)
3 views18 pages

Android Development Assignment 1

The document contains various Android program snippets that demonstrate how to perform different tasks such as checking if a number is prime, calculating factorials, generating Fibonacci sequences, and checking if a number is a palindrome. Each snippet includes a MainActivity class that extends AppCompatActivity, with methods to handle user input and display results. The code is fragmented and contains numerous typographical errors, making it difficult to read and understand fully.

Uploaded by

anuragtiwari3380
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)
3 views18 pages

Android Development Assignment 1

The document contains various Android program snippets that demonstrate how to perform different tasks such as checking if a number is prime, calculating factorials, generating Fibonacci sequences, and checking if a number is a palindrome. Each snippet includes a MainActivity class that extends AppCompatActivity, with methods to handle user input and display results. The code is fragmented and contains numerous typographical errors, making it difficult to read and understand fully.

Uploaded by

anuragtiwari3380
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

** ite an andnoid pogam to cheek a otethen givem

heemlee is byime nunben o1 not.


Cocle las MainActhvity entendls ApfComhathcvity
Editleat etl;
Beutton bt1;
TextView tlj nreate (Bumclle sauelInstame Atate)
otecteal votd
(avedJInstace8tate);
Supen. on Greate (Ritaysutactvityaaln);
SetCon temtView (Rilayout. actrity-Malnj
et1- findl ViewBy Id ([Link];
btl- firnl ViewbyTd (R td-b ton);
tl =fndiewBy+d (R-1d-Reswlt);
bti. seton UickLis temern (new View on(llkListenen)

huetk oid oncllck ( view view)


nt n Integen paye Int (et1get Texctl).to btning0;
boolean þntme =tuej
nime falie;]else
fan (inti=2; 1<n|2 ;itt)
1f (n%f= 0)

mlme false;
byneak;
3
1f (hni me)
t1-selTet( Nmlen is nine";
3
ese

tl setTent ('Nunben 1s not bine);


3
lutput
Numben
Numben

aick
Wwmben is Pnrne
Result ()
|Result
2 unite an amndnoid þaogam to find the fautanial a

Jien numben
Main Aetvity entomds hblornpat Aetvityhy
odde clas
Buton btl;
Tentviewtl) Blate)
notected void on Gleate (Baundle 8aved Instanne
sben. onlreate (saved InstanieBtate );
tet Contem Wtew (R. layout actity-main )}
et1:findyieuById (R. td-cditTen;
btl- fndvieweyId (R td·buton
tl ndl View Byld (R- [Link]
[Link] (lck listemenl new View Gnltcklistemenl)

kublia void onllIck ( view vlew)


tezenpanue [Link]) fo ktning;
Int n=In
Int fact1;
1f Cn< o)
seTent iad not de fined ");
(hFatn
tl-
3ese
fan (Int i= 13 1<zngitt)
fat- fact *i;
t1·getTemtlFactana = l +fact);

3
Qtbut
Numben 5
+ecit Test
Numben|
Dbutton (
Factanal - 120
p Ret
Resut
V-3 wlnite an Bncoroid to genen ate the Fibenacclgenies ves 4
pogm
up to a glven nwmlien ot tems
Code wlas Mainttvity ertemos Aplomhathtivi ty
Edit Teat etij
Butten btl;
Tentview tlj (Bumdle sved Insfames btate)
piotected void onlre ate
Btate);
super on reate (sawdlInstne
etCotertview (R. oysut actvity-main
eti= finol BiewBy Ld ([Link])
btl - HndViewby Id (R. id- button);
t - And view By Tol (e-id. nelt}
bt1- setenlck Listenen/new [Link] CllckLs tenenlJ

puslic void Gntlick(Vieuw vieuw)


int n Integen-pane [Link]) goktnigl
Int a-0, b=1,c3
Sting
fon(int i=1;tcn; itt)
b=fibta t " ;
Czatb;
az b

&enies: +fb);
t1-set Tent/Fibon acei

3);
3
thut
Numben of tenm:|
ickJ
Fibenacei &enes: 011 23 S&
Reyut [Reutt)
4 whi te. an Anclrold mograr to Caleulate the quane anel
ulee
ode clas Mantectivity eutemde AjHpLomhatfhtiviy
EdHTert etij
Buton bt
Tetview tJ, (Bun dle savedIns tne Btate)D
piotecteel vold Onteate
(saued nstanettate );
[Link] -maln );
setlortentView ([Link]
et1-fndPrew By Td le. rdeolit lent);
([Link] );
bt1-AndviewById renalt;
t1- finduiewBy Jd ([Link]. OncllckListenenl)
setOnlickListemenlnew View.
Btl-
View Vjew)
hud ic vold onllIk( stng);
farsointletigetTenttsto
ot n Intergen
tntsquane - n*n;
Jnt ule n n* n;
t1.6et Tent("squane

Qutput
+edi Teott
Nunben4
Nusrnben
bbutton

sguane ==16
Reut (ulee 64
(Q-s eite. am Andioid frogam to ebek
whether a

humleen is eve edd.

Cnde Cass Main Ae tivity en terols nplompathtlvity


EclitText etj
Btton btJ)
Texthiew t 1j Bumdle saved Tnstame State)
Ano tected voidl ontreate (pae
eate (savedIrstan ceBtate);
sjen on
settentewtView ([Link]-madn)}
et1- find Viewby Id ([Link] Tentl;
bt! fnd VIew ById ([Link]);
tl ftncdViewby Ld ([Link]);
btncli LkLIStenen / new Wew. nlicklisterenl)
set

kulellc void onlk(view vlew)


fntnz
Iniegen jhunseIntleti getTen()-toJtniy);
tl·setTent Nwmben s Even";

ese
Odel");
t)·set Tent("Nunben is
3

Qutput
Numben eoltTert
button

Result Nurnben is Evem


gier
6 ite am Andoid þrogram to chek whethen a
an Amstnong wnen an not.

Code, clas oin fActvity entends Ayþ lompathtivity


Edit Tert et1j
Button bt)
TentViewtlj &vedIns tanteZtate)
(Bunelle
pioteteel void bnleate
Create laveel Irstamiektte y
[Link] autvity-matnJ
setlontentiew (R-dayout
eti= inod ViewById [Link];
[Link];
btlfndview By Id
findview BýId (R. td. nesulty OnlkListenenl)
tl (new Wew.
setonCliklistemen
[Link]
onlk(View view)
void ftringl)l;
Int(et getTentl).to
nt nIniegenharse
n
, sun 0
fnt ten =n,
while (teny >0)
Sn=sun t * n ) ;
ternt tel10

(s'Numhen isAmsteg")
t1-setTet )
Bese is Not Armatrog
tlsetTent('Nunber

3
3

Qutput 1d,
ecltTet
Numbe 153
Numben
+Button
4seul Numben is Amsto
Reult
Q- uenite cm Ancoo 0gom t8 e s e gien
a (3
humben
Cocle cla Mainhctvity eatends AP CompatAtiwity
EditTet eti;
button btlj
Tertvjew tj
votd en Create (l Bundlle saed Instancebtat)
potecteol
(sand'TnstameBtate );
super. omreate ty-main)
aetivi
setlontertWiew ([Link]
edlitTent)
[Link],
et 1= VitwByTdlR. id-button;
bt1 =fnd 14R.1deutt);
t1 : fnel View by Onllickistenerl)
Bnlicklistemen/new Vieu.
bt 1. set
vi ew)
bulelrc void onllict (view
IntletigetTernt)-toSming() )
tnt n Integen. þane
tnt new O, n
while (n>0)
n n / 10

nnh0;
nev)
t1'set Tent [" Reese =1+

Heoli4Tent Nwnmben S0403J


Numben
+ button
ck
Revese 30405
oreult
lite an Ancioid pegran to aheck wthethen
an not
glven numben is halirelnenme
(ocde la Meun Attvity entends Af (onhatfrcthvity
Ecli Tet eti3
Buton btl;
Tet V)ew tls Buncle saved Initanee Btate )
(
þnoteted vold Onlneate
onlreate (savd JnstancP Btate);
suben ty-Maln 3
6etlontentView ([Link] attvi
Tent);
[Link]-edit
et 1= AndviewById [Link]);
btl= ftndviewey Ta
t1- find ViewByTe (R-Jd. ereult); onllicklistenenl)
View.
[Link] Clicksteney (new
view)
ulelhe void enik ( view
nt n =Integen paseTntletl get?
int ten = nj
while (temþ > 0)
e er 10+1;

tern tema /10;


Palindrone");
is
tl·setTent( Numben
Not Palinelrone ;
3else Numleen 's
t-set Tent (

3
Otput
Nwrmben
eolitTent |sNwmben121
obution
ick ck
breyut Nmben is Palinbnete
Swmof reult Result
-1s Digits
buttorn + ck
edHTend Numben
J456 Numben
t1- 3
digitt l"
Sumol setTent
sum); "+t -
nn/10
swrnt Swn
ln>o) while
swm nInt nt
ntlettgetText
). þanme0jnjFtegen
to8tig
}
vlew) Cview onClick vold hublid
btlesetonCtickListenenlnew
Listenen
l)view-erClIck
button) fndvieweyrd
Jd
(R. st1
findviewy4
layout-atvity
Test)ýlR'[Link] (ontentiew
CR Bet
-main)g Bupen.o
ktute); Tnstane sawed bneatel
saued (Bunde ate Cre votlprotecteol
on
kBattfrstame
) Tenthiew
t1j
bti;Button
tTemt Boli4
aihtiwity tHuity
ih Masnhetvity
lom entends cla Code
numben. plven a"gltsy
0 Bun the And to regt Avclroid wn
utsite -9
-10 lite an Android reogam to find the geatest
csen,
thee hmbens entened by the
(ode, clan Man He thvity entemds lomhathivity
EliH Teyut etl,et ), et3,
Bueton bt3,
Tent View tJ) Inctamettate)
void onbeate (Bundle 'caved
piotecteol
kHate);
Bfenonlneate(sadnstane -man);
setlentent View (R. bayout actvity
et1-ftndviewB,Td ( [Link] Tenl1);
Text2);
Ia/[Link]
et2 findviewey tcl. edi Tent3);
et3 " fndView ByTd tR.
bt] =find Viewby+d/ [Link]-button;
view. nlickListenenl)
[Link] lnew

od onllck (View wiew)


þushc tast1irg())
Irntlet-get Tertt). Stoihgl));
a:Integenhaue
int Integenpane ntlerl getTentC). to
ht Inkgeifarsegntlefgetteutl) toSting0);
hic*
it(a>bRA asc) Mumten =" ta);
t1setTent ("yneatest
Seeiflo>) Nmber= ? +b);
ates+
[Link](Mlre Nwmbey ="tc):
Bebet1getTent("yneateit

. 3
3))

Numben 1 |25
Munbern 2 Jeec Tent2 Nwmben 2 36
Nwnben3 e Tent3 Numben 15
button

Reuet esult Gveatest nben 3


(-11 nite am Ancnoid pgam to caunt the hemben
bgìts n a glvennmben. AHp(omþetpctvity
(ocle clas Main Detvity entemdh
Edit Temt eti;
&etton 6tJ;
savedInstameBtate)
Textbyew t1)
voidd onCopatc (Bundle
bejotected
suhenonlreate (savcdTnstanieftateJ:
autity-maln);
sefC®ntentiew/k. la uout.
editTent)
findviewByTd([Link]);
fndview Bid [Link]
bt1 14 [Link]. nenl4)
tJ findviewBy
Onllikistenenlnew VWew.
Bnlicklistenenl)
[Link]
onlick (view view)
pubtic vold getTent ).toUjnigl
IntegenpanseTnted
n =0;
intnt cownt
if Cn=o)
Coount- 1;
3else
whle (n>o)
countttj
ninho;

digts
"ytsunt);
.setTent (si Numbern of
3

Nuraten
+etTemt Nmbe 135698 9
butlon

Lo,ult elt Numben o digits 7


yeay leat Yean
is
Pbutton
cvy2024 Ye yean
Temt +edil
Jd,
t1setTet
yeay ('
is 3else
yea)j leat rota
is Tet t6et
"} Leap ("yean
Yean if(Cyean6=:0B&
|-o)|i
foo (yean7 j00 yeane
Irtegen,ham yean: nt
tetlgetTentl).
tomingl tok
1;
view) View enllick( vOldBuallc
clcklistenenC listenenlnew $tlsetonClick
t1
[Link]; (R. Byt4 view bt1
LR:d. View
LdBy fol
buton)
([Link]
setontentView
a
(sacel Cneate super:
on
Tnstame onlroa voidotecteol
(Bunolle te
te) tanesavedTns
bt1) tton Bu
hethvihy Meur class Code
not. yeano leap
cohetthen to
<heck þogamo
aheck to Aydneid an
ue1ite (-12
(0-13S_ulyite m Annoid rogam to Cenvent tempenatwe
trem Celsies to Fahnenhet.
Manhetvity entends hj Compathhvity
Code, clays
Ecli+ Temt et1)
Button btl;
Tentiew t!) dle saved Instameitate)
(Bun
brotected vold onreate Btat);
onoeate (uauedIngtane
supen lRlayout. atvity-main))
set (ontentiew ([Link]
ByJd
et1 findview ( [Link].
. button)
Ia
bts-find ViewByTdR.d. ne); Vlew-rlickListenenl)
t1=And WewBytenen(new
bt1-setolickis view)
vo1d onUick ( View
kuldc [Link]).to
Flat. bayseEloat
flout celalus stningl);
float fahnenheit;
(celuus *9 /5 )+32;
?tfahrenhett ;
fatrenhejt =
Fahnen heit =
t1 setTent (6

3
(otput
editest Celsius 25
|Celsls
buton

eult Fahenheit =734


Result
(15)
uite cn Andhaid jrcgam to calelate mple
Interest wsiny sen input.
(ode
ctau Mainhcivity entends lohathtity
Eal1 t Tent et1et2,et3;
Button bt1j
Temtew tl) (eundlle savcdInstamceßtate)
notected votd Gnneate
[Link] (saudTntancestute);
-main ;
setlontentiow lR. layoutactivity
ftrelviewByTad [Link] Teat1))
e41 ByJol ([Link] Tent);
et2 =find Uiew Tent3);
et3findviewByIol /[Link]-edit
bt1-findviewByLd CR-id button
tifindView8yTo
Id (R-][Link]); ViewOnclcklistenen)
bt1etonlicklis tenen new
(Veo view)
clck
bulelic void Tent().to String();
float,panyefleutlettyellest(-toSming(0)
float b = farseEloat(e+[Link]
flouti Float etiget Text) to8 blngC)
Eloatt
tloat t Eloat}are
/bglrmyle Inteest " +si);
tlsetTent
3
3)
3

Qutpuct d,
editTent1 Priral lo00
Pincihal HeelHTent2 Rate
Rate Tme
HodtLet3
Time
button
CIck
neult Ssnle Tnterest 100.+
ROult
uenite an Andnord ogran to swat two rwmlers (16)
without using a th nd vanlable
Hctvity entends ty lemyathctvity
(ode
oae, oay Main
Fdi Tent et,et 2)
Button jtl)
Tetnew t1} Tatamcebtate)
(Bun dle Rrd
boteted vold en(eate Jstncestate);
(souwesl
Butenon Create ([Link] -main
actvity
BetContentView (d.edtTen1):
et1=frc ViewbyIdIa ([Link].etTent2)
et2 fndviewby byId |[Link]. button);
btifincview
findiew by Id ([Link]); icklistemen))
t1
btlgeenlicklistenen(new [Link]
void onlick(View vlew)
bublic () ing
Integen.þaueInt(et1. getTent()-toßtr
tnt a - harue intlet2,getest). te piningny
tnt b=Irtegen
azatb
b=a-b
aa-b nA
[Link] l Aften kwaþing:
t at
J
3);
3
3

A L A 5
edHTent2
B B| 10
+button
lcerck
feult eult ften bwating:
B= S
pnogtam to disfeay all pnie
Amdnoid wmbes.
Cocle betureem too glven
entends Bb (omfatptig
clas Mainhetvit
Edit Tent eti,et)
Button bt1) Atate )
Tetview t1j (Eavcanstane,
notectel vo1d onteateativity -main
3etContentWew/e. layout
trtd.eolifTent1);
etL ind view By Id (R.
[Link].edtTemt2)
et2-fnd viewB Id
ldbutton;
bti- finlviewByrd (B.,td-result) IckLtenenC)
tl: firel View By Id (R
getonllck Listenen lnew v)ew. Oncl
bti-
onclck lview view) g0
pullic void TntlegetTest().to8tbigl
have let2getText[)-to
Integen
ntstant
end-Integeparse Fnt
t be bime Nungberss"
Bbing erult
tant; I<5ond; it+)
fan ( intizs
1fli>1)
oleam mine =tues
bo
tan(int j: 23j<=i/23tt)

þme- false
neak)
3
f(pnime)

3
[Link] Tert(esul);

);
(18
Qutput
8tant Numben +edtTentl Btant Nunben 10
En ol Nwmben edH Tent2
End Numben 30
button
Chck lcerck
prlme nwmbers:
Result Deyult 41 L3 17 19 23 24

You might also like