A. Introduction
do loops are essentially same at while loops except that they will run at least once. All three types of loops can be converted into each other... Which one to choose?
B. Watch(slides)
C. Try this:
Write while loops to solve E6.4 and E6.6, then convert them to Do loops.
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("how many numbers you gon input?");
int y = in.nextInt();
int sum = 0;
int previous_in = 0;
int i = 0;
do{
int x = in.nextInt();
sum += x;
if(x == 0 || x == previous_in){
break;
}
previous_in = x;
i++;
}while (i < y);
System.out.println(sum);
}
}