Question: Self-Check Problems Section 2.1: Basic Data Concepts 1. Which of the following are legal int literals? 221.51 2.310.05.-68753097 2. What is the result of the
Self-Check Problems Section 2.1: Basic Data Concepts 1. Which of the following are legal int literals? 221.51 2.310.05.-68753097 2. What is the result of the following expression? 1+2*3+7*2%5 a.1 b.2 c.5 d.11 e.21 3. Trace the evaluation of the following expressions, and give their resulting values . 2 + 3 * 4-6 . 14 / 7 * 2 + 30 / 5+1 C. (12 + 3) / 4 2 d.(238 % 10 + 3) 87 e" (18-7) * (43 % 10) f, 2 + 1985-(11 * (5 / 2)) g, 813 % 100 / 3 + 2.4 h, 26 % 10 % 4 * 3 g. "hello 3424 h. 2(int) 2.0" 2 2 2 i. 4+19-3 10) +11 1 3 J 8+6-2 4 (25) k. 1 + 1 8 2" (8 2)11 L 5+2 (1 1)" + 423 m.1 2 3 4" 5 67 (89) Section 2.2: Variables 6. Which of the following choices is the correct syntax for declaring a real number variable named grade and initializing its value to 4.0? a. int grade 4.0 b. grade double 4.0 c. double grade 4.0 d. grade 4 e. 4.0 grade1 12. What is the value of variable x after the following code executes? int x = 3; x=x+2; x=x+x; d. 10e. 12 13. What are the values of a, b, and c after the following statements? int a 5; int b 10 int a bi a a + 1 14. What are the values of first and second at the end of the following code? How would you describe the net effect of the code statements in this exercise? int first -8 int second 19; first first + second second first second first first- second; 12 13 14 15 16 System.out.println("My taxes owed:")i//208 tax System.out println( (4 5 +8 4) 8.750.20) 21. Complete the following code, replacing the "FINISH ME" parts with your own code: public class Count2 public static void main(Stringt args) ( for (int i/FINISH ME.) t system.out.println(/ FINISH ME /) 124 Chapter 2 Primitive Data and Definite Loops to produce the following output: 2 times 1 2 2 times 2 4 2 times 3 6 2 tines 4-8 z times 4-8 22. Assume that you have a variable called count that will tike on the values I. 2. 3, 4, and so on. You are going to in terms of count that will yield different sequences. For example, to get the sequence 2, 4, in the following table, jindicating an expres- 6, 8, 10, 12,..., you would use the expression (2 sion that will generate each sequence. count ). Fill in the following table, Sequence a. 2,4, 6,8, 10, 12, b. 4, 19, 34, 49,64,79,... c. 30, 20, 10, 0, 10, 20,... Expression e. 97,94, 91, 88, 85, 82,... 23. Complete the code for the following for loop: for (int i-li i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
