Java question. if i=10 the output is xyxyyxy, i am having trouble tracing what happens to the string values.?
signific java.util.Protection;
public class Conditionals
public static avoid main(String args)
Protection in = fresh Scanner(System.in);
int we = throughout.nextInt();
Chain s = “x”;
Chain t = “y”;
whenever (i >= 12 && post <= 20)
utes = verts + t;
otherwise if (i = 30)
utes = capital t + azines;
otherwise if (i >= 25)
utes = verts + azines;
else
utes = capital t + t;
whenever (i % 5 == 0)
to = verts + t;
Method.out.println(s+t);
i=10 and so first condition is true
s=”x”+”y”;
s=”xy”;
now i%5 is add up to 0
so
t=”xy”+”y”;
t=”xyy”;
+add
now i%3 is usually 1 which can be not equal to 0 and so condition turns into true
t=”xyy”+”xy”;
t=”xyyxy”;
these days print assertion will print
xyxyyxy
which can be the answer
t=”xyyxy”;
Its very simple.When you input EIGHT, then
whenever (i >= 12 && post <= 20)
utes = verts + t;
is definitely executed.
The following s=s+t
we.e s=xy Because s = times, t =y
Subsequently it occurs to
if (i PER-CENT 5 == 0) Which can be true, for this reason t=s+t
to = verts + t;
we.e t=xyy s=xy capital t = y => xyy
subsequently finally s+t is actually displayed
s= xy to =xyy
we.e.xyxyy
This output is actually xyxyy possibly not xyxyyxy i highly recommend you recheck.
With thanks.Hope it helps
If you will be running that in Eclipse or many similar IDE cannot you phase through it using the debugger.
Leave a Reply
You must be logged in to post a comment.