Question 8

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Quest

ion8:

i
mpor tjava.
ut i
l.Scanner;
classPr ogram8
{
publ icst at
icv oidmai n(Stri
ngar gs[])
{
Scannersc=newScanner( System. i
n);
i
ntn, ch,r,
se=0,f=1,i
;
Sy stem. out.printl
n("
1f orSum ofev endi git
s");
Sy stem. out.printl
n("
2f orFactor i
aloft henumber ")
;
Sy stem. out.printl
n("
Ent eryourchoi ce:")
;
ch=sc. nextI
nt();
Sy stem. out.printl
n("
Ent eranumber :"
);
n=sc. nextI
nt();
swi tch( ch)
{
case1:
whi le( n>0)
{
r=n%10;
i
f( r%2==0)
se=se+r ;
n=n/ 10;
}
Sy stem. out.printl
n("
Sum ofev endi gi
ts:"+se);
case2:
for( i
=1; i
<=n;i++)
f=f*i;
Sy stem. out.printl
n("
Fact ori
aloft henumber :
"+f)
;
def aul t
:
Sy stem. out.printl
n("
Invalidchoice");
}
}
}

You might also like