Вы находитесь на странице: 1из 3

1.

pri
ntchar
ect
erpat
ter
n charch='
a'
;
charpr
int=ch;
I
nput
: f
or(
i=0;
i
<=num;
i
++)
5 {ch=pr
int
;
Expect
edout
put
: f
or(
j=0;
j
<=i
;
j++)
a {
ab pr
int
f(“
%c”
,ch++)
;
abc }
abcd pr
int
f("
\n")
;
abcde }
t
est
case2: }
i
nput
: }
1
Out
put
:
a 2.
Youar
erequi
redt
ofi
xal
ll
ogi
cal
err
orsi
nthegi
ven
code.Youcancl
i
ckonCompi
l
e,Runany
timet
o
i
ntchar
act
erpat
ter
n() checkt
hecompi
l
ati
on/
execut
ionst
atusoft
hepr
ogr
am.
{ YoucanuseSy
stem.
out
.pr
int
lnt
odebugy
ourcode.
i
ntpr
int
char
ect
erpat
ter
n(i
ntnum) Thesubmitt
edcodeshouldbelogi
cal
l
y/sy
ntact
ical
l
y
{ cor
rectandpassal
ltest
cases.Donot

i
nti
,
j; wr
it
ethemai
n()f
unct
ionasi
tisnotr
equi
red.
CodeAppr
oach:
Fort
hisquest
ion,
youwi
l
lneedt
o case1:
cor
rectt
hegiv
eni mpl
ementati
on.Wedonotexpecty
out
o pr
int
f("
red"
);
modifyt
heapproachori
ncorpor
ate br
eak;
anyaddi
ti
onal
li
brar
ymet
hods. case2:
Themet
hodpr
int
Col
or(
int
num)oft
hecl
assCol
ori
s pr
int
f("
black"
);
supposedt
opr
intnamesofcol
oraccor
dingt
ogi
ven br
eak;
i
nputnumbersnum Whent
hev
aluesofnum equal
1,2,
3,
4 case3:
t
hefunct
ionpri
nts
pr
int
f("
whi
te"
);

Red”,
”Bl
ack”
,”
Whit
e”,
”Gr
een”r
espect
ivel
yforanyot
her
v
aluesofnum i
t br
eak;

shoul
dpr
int“
Nocol
or”
. case4:

Themet
hodcompl
i
esf
inebutf
ail
stor
etur
nthedesi
red pr
int
f("
green"
);

r
esul
tsf
orsomecases br
eak;

Yourt
aski
stof
ixcodesot
hati
tpassesal
lthe def
aul
t:

t
est
cases pr
int
f("
nocol
or"
);
br
eak;

i
ntcol
or }

{ }

i
ntpr
int
col
or(
intnum) }

{ 3.

swi
tch(
num) Themet
hodpr
int
pat
ter
n(i
nt)ofcl
assdr
awpat
ter
nis

{ expect
edt
oexpect
edt
opr
intt
hef
ir
stn(
n>0)
Li
nesoft
hepat
ter
n {
TESTCASES i
nti
,
j,
pri
nt=1;
Test
Case1 f
or(
i=1;
i
<=n;
i
++)
I
nput
: f
or(
j=1;
j
<=2*i
;
j++)
4 {
Expect
edRet
urnv
alue: pr
int
f(“
%d”
,pr
int)
;
11 }
1111 pr
int
f(“
\n”
);
111111 }
11111111 }
Test
Case2:
I
nput
:
1
Expect
edRet
urnVal
ue:
11

i
ntdr
awpat
ter
n
{
i
ntpr
int
pat
ter
n(i
ntn)

Вам также может понравиться