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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started