151k views
2 votes
Consider the following two code segments: Segment 1: while (k > 0) { System.out.println(k); k--; } --------------- Segment 2: while (k > 0) { System.out.println(k); k--; } while (k > 0) { System.out.println(k); k--; } Assume that in both cases variable k has the same initial value. Under which of the following conditions will the two code segments produce identical output.

User Rajohan
by
6.2k points

1 Answer

2 votes

Answer:

Always same value

Step-by-step explanation:

These both code segments will always generate identical values given that we provide same value of k to both segments.

You can see attached pictures.

Consider the following two code segments: Segment 1: while (k > 0) { System.out-example-1
Consider the following two code segments: Segment 1: while (k > 0) { System.out-example-2
Consider the following two code segments: Segment 1: while (k > 0) { System.out-example-3
User Kcbanner
by
4.7k points