Question: 16. How do you generate the following printout, using the boxString method? ------- !Hello! ------- ------- !World! ------- 17. What is wrong with the following

16. How do you generate the following printout, using the boxString method?

-------

!Hello!

-------

-------

!World!

-------

17. What is wrong with the following statement?

System.out.print(boxString("Hello"));

21. Consider the following statements: int totalPennies = (int) Math.round(100 * total) % 100; int taxPennies = (int) Math.round(100 * (total * taxRate)) % 100;

Introduce a method to avoid code duplication.

Consider the program for questions 31-35:

1 public class Sample

2 {

3 public static void main(String[] args)

4 {

5 int x = 4;

6 x = mystery(x + 1);

7 System.out.println(s);

8 }

9

10 public static int mystery(int x)

11 {

12 int s = 0;

13 for (int i = 0; i < x; x++)

14 {

15 int x = i + 1;

16 s = s + x;

17 }

18 return s;

19 }

20 }

31. Which lines are in the scope of the variable i declared in line 13?

32. Which lines are in the scope of the parameter variable x declared in line 10?

33. The program declares two local variables with the same name whose scopes don't overlap. What are they?

34. There is a scope error in the mystery method. How do you fix it?

35. There is a scope error in the main method. What is it, and how do you fix it?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!