Exercises 4.10 Compare and contrast the if single-selection statement and the while repetition statement. How are these two statements similar? How are they different?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hello Sir. Good Morning.

I have a questions in my homeword related computer programming lesson.

The following below is questions. Please advice. Thank you

Exercises
4.10
Compare and contrast the if single-selection statement and the while repetition statement.
How are these two statements similar? How are they different?
146
Chapter 4 Control Statements: Part I; Assignment, ++ and
- Operators
4.11
Explain what happens when a Java program attempts to divide one integer by another.
What happens to the fractional part of the calculation? How can you avoid that outcome?
4.12
Describe the two ways in which control statements can be combined.
4.13
What
type of repetition would be appropriate for calculating the sum of the first 100 posi-
tive integers? What type would be appropriate for calculating the sum of an arbitrary number of pos-
itive integers? Briefly describe how each of these tasks could be performed.
4.14
What is the difference between preincrementing and postincrementing a variable?
4.15
Identify and correct the errors in each of the following pieces of code. [Note: There :
may
be
more than one error in each piece of code.]
a) if (age >= 65);
System.out.println("Age is greater than or equal to 65");
else
System.out.println("Age is less than 65)";
b) int x = 1, total;
while (x <= 10)
{
total += x;
++x;
}
c) while (x <= 100)
total += x;
++x;
d) while (y > 0)
{
System.out.println(y);
++y;
4.16
What does the following program print?
// Exercise 4.16: Mystery.java
2
public class Mystery
3
{
public static void main(String[] args)
{
int x = 1;
int total = 0;
7
8
9
while (x <= 10)
10
II
int y = x * x;
System.out.println(y);
total += y;
12
13
14
++X;
15
}
16
17
System.out.printf("Total is %d%n", total);
}
} // end class Mystery
18
19
Transcribed Image Text:Exercises 4.10 Compare and contrast the if single-selection statement and the while repetition statement. How are these two statements similar? How are they different? 146 Chapter 4 Control Statements: Part I; Assignment, ++ and - Operators 4.11 Explain what happens when a Java program attempts to divide one integer by another. What happens to the fractional part of the calculation? How can you avoid that outcome? 4.12 Describe the two ways in which control statements can be combined. 4.13 What type of repetition would be appropriate for calculating the sum of the first 100 posi- tive integers? What type would be appropriate for calculating the sum of an arbitrary number of pos- itive integers? Briefly describe how each of these tasks could be performed. 4.14 What is the difference between preincrementing and postincrementing a variable? 4.15 Identify and correct the errors in each of the following pieces of code. [Note: There : may be more than one error in each piece of code.] a) if (age >= 65); System.out.println("Age is greater than or equal to 65"); else System.out.println("Age is less than 65)"; b) int x = 1, total; while (x <= 10) { total += x; ++x; } c) while (x <= 100) total += x; ++x; d) while (y > 0) { System.out.println(y); ++y; 4.16 What does the following program print? // Exercise 4.16: Mystery.java 2 public class Mystery 3 { public static void main(String[] args) { int x = 1; int total = 0; 7 8 9 while (x <= 10) 10 II int y = x * x; System.out.println(y); total += y; 12 13 14 ++X; 15 } 16 17 System.out.printf("Total is %d%n", total); } } // end class Mystery 18 19
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY