What are the difference beetwen a while loop and a do-while loop? Convert the following while loop into a do-while loop. int i = 1; while (i < 10) if (i % 2 ==
TI
renardypratama
Pertanyaan
What are the difference beetwen a while loop and a do-while loop? Convert the following while loop into a do-while loop.
int i = 1;
while (i < 10)
if (i % 2 == 0)
System.out.println(i);
(b)
int i = 1;
while (i < 10)
if (i % 2 == 0)
System.out.println(i++);
(c)
int i = 1;
while (i < 10)
if ((i++) % 2 == 0)
System.out.println(i);
int i = 1;
while (i < 10)
if (i % 2 == 0)
System.out.println(i);
(b)
int i = 1;
while (i < 10)
if (i % 2 == 0)
System.out.println(i++);
(c)
int i = 1;
while (i < 10)
if ((i++) % 2 == 0)
System.out.println(i);
1 Jawaban
-
1. Jawaban kurniadi
While, mengecek Kondisi if terlebih dahulu sebelum looping.
do while, mengecek looping terlebih dahulu sebelum kondisi if nya .
a. int i = 1;
do {
if (i % 2 == 0) {
System.out.println(i++);
}
}
while(i < 10);
^ Samakan untuk b dan c :)