+1 vote
in Class 12 by kratos

Write the code given below using 'for' loop instead of 'while' loop :

int i = 1;

while (i < = 5)

{

if (i * i == 4)

jTextField1. setText (" " + i);

i = i + 1;

}

1 Answer

+1 vote
by kratos
 
Best answer

Following code using for loop :

int i;

for (i = 1; i < 5; i++)

{

if (i * i == 4)

 jTextField1.setText (" " + i);

}

...