In: Computer Science
Use Java to rewrite the following pseudo-code segment using a loop structure without goto, break, or any other unconditional branching statement:
k = (j+13)/27; //assume i,j,k are integers properly declared.
loop:
if k > 10 then goto out
k=k+1.2;
i=3*k-1;
goto loop;
out: …
public class TestLoop {
public static void main(String[] args) {
double j = 5, i = 0;
double k = (j + 13) / 27.0; //
assume i,j,k are integers properly
//
declared.
// loop untill k is <10 which replaces the go to statement
while (k < 10) {
k = k +
1.2;
i = 3 * k -
1;
}
System.out.println(i);
System.out.println(j);
System.out.println(k);
}
}