Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that uses a while loop to print the integers 1 to 100, one number on each line, and set the numbers field

Write a program that uses a

while

loop to print the integers 1 to 100,

one number on each line, and set the numbers field width as 3. When a number is

divisible by 3, print Blue on the same line, and separate them by a space. Follow the

same format, when a number is divisible by 5, print Berry; and when a number is

divisible by 15, print Blueberry. Note that a number divisible by 15 will also be

divisible by 3 and 5. In this case, only Blueberry should be printed. A message, The

following is from a

while

loop, should be printed on the first line. Three messages, one

on each line, should be printed to report the total numbers of Blue, Berry, and

Blueberry respectively. Finally, in the same program, add a

for

loop and a

do...while

loop: each accomplishes the same task as the

while

loop. The output of your program

should look exactly like the following:

The following is from a while loop:

1

2

3 Blue

4

5 Berry

6 Blue

7

8

9 Blue

10 Berry

11

12 Blue

13

14

15 Blueberry

16

17

18 Blue

19

20 Berry

21 Blue

22

23

24 Blue

25 Berry

26

27 Blue

28

29

30 Blueberry

31

32

33 Blue

34

35 Berry

36 Blue

37

38

39 Blue

40 Berry

41

42 Blue

43

44

45 Blueberry

46

47

48 Blue

49

50 Berry

51 Blue

52

53

54 Blue

55 Berry

56

57 Blue

58

59

60 Blueberry

61

62

63 Blue

64

65 Berry

66 Blue

67

68

69 Blue

70 Berry

71

72 Blue

73

74

75 Blueberry

76

77

78 Blue

79

80 Berry

81 Blue

82

83

84 Blue

85 Berry

86

87 Blue

88

89

90 Blueberry

91

92

93 Blue

94

95 Berry

96 Blue

97

98

99 Blue

100 Berry

There are 27 Blues.

There are 14 Berries.

There are 6 Blueberries.

The following is from a for loop:

1

2

3 Blue

4

5 Berry

6 Blue

7

8

9 Blue

10 Berry

11

12 Blue

13

14

15 Blueberry

16

17

18 Blue

19

20 Berry

21 Blue

22

23

24 Blue

25 Berry

26

27 Blue

28

29

30 Blueberry

31

32

33 Blue

34

35 Berry

36 Blue

37

38

39 Blue

40 Berry

41

42 Blue

43

44

45 Blueberry

46

47

48 Blue

49

50 Berry

51 Blue

52

53

54 Blue

55 Berry

56

57 Blue

58

59

60 Blueberry

61

62

63 Blue

64

65 Berry

66 Blue

67

68

69 Blue

70 Berry

71

72 Blue

73

74

75 Blueberry

76

77

78 Blue

79

80 Berry

81 Blue

82

83

84 Blue

85 Berry

86

87 Blue

88

89

90 Blueberry

91

92

93 Blue

94

95 Berry

96 Blue

97

98

99 Blue

100 Berry

There are 27 Blues.

There are 14 Berries.

There are 6 Blueberries.

The following is from a do...while loop:

1

2

3 Blue

4

5 Berry

6 Blue

7

8

9 Blue

10 Berry

11

12 Blue

13

14

15 Blueberry

16

17

18 Blue

19

20 Berry

21 Blue

22

23

24 Blue

25 Berry

26

27 Blue

28

29

30 Blueberry

31

32

33 Blue

34

35 Berry

36 Blue

37

38

39 Blue

40 Berry

41

42 Blue

43

44

45 Blueberry

46

47

48 Blue

49

50 Berry

51 Blue

52

53

54 Blue

55 Berry

56

57 Blue

58

59

60 Blueberry

61

62

63 Blue

64

65 Berry

66 Blue

67

68

69 Blue

70 Berry

71

72 Blue

73

74

75 Blueberry

76

77

78 Blue

79

80 Berry

81 Blue

82

83

84 Blue

85 Berry

86

87 Blue

88

89

90 Blueberry

91

92

93 Blue

94

95 Berry

96 Blue

97

98

99 Blue

100 Berry

There are 27 Blues.

There are 14 Berries.

There are 6 Blueberries.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started