Computer Applications
Convert the following for loop segment to an exit-controlled loop.
for(k = 10;k >= -1;k--)
System.out.println(k*2);
System.out.println(k*4);
Java Iterative Stmts
1 Like
Answer
k = 10;
do {
System.out.println(k * 2);
k--;
} while (k >= -1);
System.out.println(k * 4);
Answered By
1 Like
Related Questions
Write Java statements for the following:
(a) To assign the cube root of -343 to a variable with the appropriate datatype.
(b) To assign the position of the last occurrence of @ in the String s with the appropriate datatype.Mention the output of this code snippet:
int lives = 5; System.out.println(lives--); System.out.println(lives);Give the output of the following program segment:
int x[]={2,45,7,67,12,3}; int i, t=0; for(i=0, t=5;i<3;i++,t--) { System.out.println(x[i]+x[t]); }Write Java statements for the following:
(a) Initialise the array with the three favourite subjects.
(b) Declare an array to store the marks in 3 subjects of 40 students.