Java Reference
In-Depth Information
(e) Executes body 3 times.
Output is
2 4 16
(f) Executes body 5 times.
Output is
bbbbbabbbbb
(g) Executes body 7 times.
Output is
10
5
2
1
0
0
0
(h) Executes body 3 times.
Output is
/\/\/\/\/\/\/\/\
9. Scanner console = new Scanner(System.in);
String response;
do {
System.out.println(
"She sells seashells by the seashore.");
System.out.print("Do you want to hear it again? ");
response = console.nextLine();
} while (response.equals("y"));
10. public static int zeroDigits(int number) {
int count = 0;
do {
if (number % 10 == 0) {
count++;
}
number = number / 10;
} while (number > 0);
return count;
}
11. Scanner console = new Scanner(System.in);
Random rand = new Random();
int num;
do {
num = rand.nextInt(1000);
System.out.println("Random number: " + num);
} while (num < 900);
Search WWH ::




Custom Search