Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I Need 2.6 , 2.7 and 2.8 Answer the following questions based on Chapter 2 in th

ID: 3753088 • Letter: I

Question

I Need 2.6 , 2.7 and 2.8

Answer the following questions based on Chapter 2 in the text. [10 points each] 1. This Java reserved word is used to define a constant: 2. Using an undeclared variable is a run-time error. True or False? 3. Dividing two integers will always result in an integer in Java. True or False? 4. To raise a value to a power use the library function called 5. The String method that returns the length of a string is called Answer the following. [3 pts each; total 48 points] R2.6 What are the values of the following expressions, assuming that n is 17 and m is 18? a, n / 10 + n % 10 b, n % 2 + m962 C. (m + n)/2 d, (m + n) / 2.0 e. (int) (0.5(m n)) f. (int) Math.round (0.5 (mn) R2.7 What are the values of the following expressions? In each line, assume that String s-"Hello" String t"World" a. s.lengthO t.lengthO b.s.substring(1, 2) c. s.substring(s.1engthO / 2, s.lengthO) R2.8 Find at least five comptle-ttme errors in the following program public class HasErrors public static void main System.out.print (Please enter two numbers:) x-in.readDouble; y-in.readDouble; System.out.printline("The sum is "+x +y);

Explanation / Answer

1. final
2. False. It gives compilation error
3. True. 2 integers divide to give an integer
4. mathematical operations are done using Math library
5. length() returns string length


2.6

n = 17
m = 18

a. n/10 + n%10 = 1+7 = 8
b. n%2 + m%2 = 1+0 = 1
c. (m+n)/2 = 35/2 = 17
d. (m+n)/2.0 = 35/2.0 = 17.5
e. (int)(0.5*(m+n)) = (int)(0.5*(35)) = (int)17.5 = 17
f. Math.round round the result 17.5 to 17

2.7
String s = "Hello";
String t = "World";
a. s.length()+t.length() = 5+5 = 10
b. s.substring(1,2) = "e"
c. s.substring(s.length()/2,s.length()) = s.substring(2,5) = "llo"
d. s+t = "HelloWorld"
e t+s = "WorldHello"

2.8
main method takes String[] argument
; is not needed at the end of main method
Print message should be enclosed in double quotes
Scanner object in is not declared
printline method is not defined.