1. Java expressions. What is the value of each of the following Java expressions? To express...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Java expressions. What is the value of each of the following Java expressions? To express your answer, write a Java literal of the appropriate type, such as 0, 0.0, false, or "0". If an expression results in a compile-time or run-time error, write ERROR for its value. Assume that the variables x, y, and z have been initialized as follows: int x = 2; int y = 3; int z = 4; Java expression X z+y/y + x x*y/z* z (z < x) && (z < y) || (x < y < z) (z y 1.0) (z x 2.0) - (double) (y / x) value 2 2. Java basics. Suppose that the variables a, b, c are of type int. (a) Complete the following code fragment so that, after the last statement, the variable max contains the largest of the three values. In each blank, write one of a, b, c, or max. You may use each variable name once, more than once, or not at all. int max = a; if ( if (- (b) Complete the following code fragment to rotate the variables a, b, and c: after the last statement, b should store the old value of a; c should store the old value of b; and a should store the old value of c. In each blank, write one of a, b, c, or temp. You may use each variable name once, more than once, or not at all. int temp = a; 3. Loops and debugging. What is the value of the variable count immediately after executing each of the following code fragments? For each code fragment at left, choose the best-matching letter at right. You may use each letter once, more than once, or not at all. int n = 10; int count = 0; for (int i = 0; i<n; i++) { count++; for (int j 0; j<n; j++) { count++; } } int n = 10; int count = 0; for (int i = 0; i <= n; i++) count++; for (int j = 0; j<n; j++) count++; int n = 10; int count = 0; int i = 1; while (i <= n) { count++; int j = 0; while (j<= n) { count++; j++; A. 0 B. 1 C. 2 D. 10 E. 11 F. 20 G. 22 H. 40 I. 100 J. 110 K. 120 L. 132 M. 220 N. 242 O. infinite loop P. run-time error 4. Properties of Java. (a) Which of the following are features of Java types and variables? Mark each statement as either true or false. true false You must declare each variable to have a specific type, but you can change its type with a subsequent declaration statement. You will get a compile-time error if you attempt to assign any value of type double to any variable of type int. You will get a compile-time error if you use any variable in an ex- pression before it has been declared. You will get a run-time error if you attempt to use any variable in an expression before it has been initialized. You will get a compile-time error if one operand of the multiplication operator (*) is of type int and the other is of type double. (b) Which of the following are advantages of using StdIn instead of command-line arguments? Mark each statement as either advantage or not advantage. advantage not advantage O You can enter input data while your program is executing. You can execute your program using different input data without having to recompile it. Your program can process the input data in reverse order. Your program can process huge amounts of input data more than can be stored in memory at any one time. 1. Java expressions. What is the value of each of the following Java expressions? To express your answer, write a Java literal of the appropriate type, such as 0, 0.0, false, or "0". If an expression results in a compile-time or run-time error, write ERROR for its value. Assume that the variables x, y, and z have been initialized as follows: int x = 2; int y = 3; int z = 4; Java expression X z+y/y + x x*y/z* z (z < x) && (z < y) || (x < y < z) (z y 1.0) (z x 2.0) - (double) (y / x) value 2 1. Java expressions. What is the value of each of the following Java expressions? To express your answer, write a Java literal of the appropriate type, such as 0, 0.0, false, or "0". If an expression results in a compile-time or run-time error, write ERROR for its value. Assume that the variables x, y, and z have been initialized as follows: int x = 2; int y = 3; int z = 4; Java expression X z+y/y + x x*y/z* z (z < x) && (z < y) || (x < y < z) (z y 1.0) (z x 2.0) - (double) (y / x) value 2 2. Java basics. Suppose that the variables a, b, c are of type int. (a) Complete the following code fragment so that, after the last statement, the variable max contains the largest of the three values. In each blank, write one of a, b, c, or max. You may use each variable name once, more than once, or not at all. int max = a; if ( if (- (b) Complete the following code fragment to rotate the variables a, b, and c: after the last statement, b should store the old value of a; c should store the old value of b; and a should store the old value of c. In each blank, write one of a, b, c, or temp. You may use each variable name once, more than once, or not at all. int temp = a; 2. Java basics. Suppose that the variables a, b, c are of type int. (a) Complete the following code fragment so that, after the last statement, the variable max contains the largest of the three values. In each blank, write one of a, b, c, or max. You may use each variable name once, more than once, or not at all. int max = a; if ( if (- (b) Complete the following code fragment to rotate the variables a, b, and c: after the last statement, b should store the old value of a; c should store the old value of b; and a should store the old value of c. In each blank, write one of a, b, c, or temp. You may use each variable name once, more than once, or not at all. int temp = a; 3. Loops and debugging. What is the value of the variable count immediately after executing each of the following code fragments? For each code fragment at left, choose the best-matching letter at right. You may use each letter once, more than once, or not at all. int n = 10; int count = 0; for (int i = 0; i<n; i++) { count++; for (int j 0; j<n; j++) { count++; } } int n = 10; int count = 0; for (int i = 0; i <= n; i++) count++; for (int j = 0; j<n; j++) count++; int n = 10; int count = 0; int i = 1; while (i <= n) { count++; int j = 0; while (j<= n) { count++; j++; A. 0 B. 1 C. 2 D. 10 E. 11 F. 20 G. 22 H. 40 I. 100 J. 110 K. 120 L. 132 M. 220 N. 242 O. infinite loop P. run-time error 3. Loops and debugging. What is the value of the variable count immediately after executing each of the following code fragments? For each code fragment at left, choose the best-matching letter at right. You may use each letter once, more than once, or not at all. int n = 10; int count = 0; for (int i = 0; i<n; i++) { count++; for (int j 0; j<n; j++) { count++; } } int n = 10; int count = 0; for (int i = 0; i <= n; i++) count++; for (int j = 0; j<n; j++) count++; int n = 10; int count = 0; int i = 1; while (i <= n) { count++; int j = 0; while (j<= n) { count++; j++; A. 0 B. 1 C. 2 D. 10 E. 11 F. 20 G. 22 H. 40 I. 100 J. 110 K. 120 L. 132 M. 220 N. 242 O. infinite loop P. run-time error 4. Properties of Java. (a) Which of the following are features of Java types and variables? Mark each statement as either true or false. true false You must declare each variable to have a specific type, but you can change its type with a subsequent declaration statement. You will get a compile-time error if you attempt to assign any value of type double to any variable of type int. You will get a compile-time error if you use any variable in an ex- pression before it has been declared. You will get a run-time error if you attempt to use any variable in an expression before it has been initialized. You will get a compile-time error if one operand of the multiplication operator (*) is of type int and the other is of type double. (b) Which of the following are advantages of using StdIn instead of command-line arguments? Mark each statement as either advantage or not advantage. advantage not advantage O You can enter input data while your program is executing. You can execute your program using different input data without having to recompile it. Your program can process the input data in reverse order. Your program can process huge amounts of input data more than can be stored in memory at any one time. 4. Properties of Java. (a) Which of the following are features of Java types and variables? Mark each statement as either true or false. true false You must declare each variable to have a specific type, but you can change its type with a subsequent declaration statement. You will get a compile-time error if you attempt to assign any value of type double to any variable of type int. You will get a compile-time error if you use any variable in an ex- pression before it has been declared. You will get a run-time error if you attempt to use any variable in an expression before it has been initialized. You will get a compile-time error if one operand of the multiplication operator (*) is of type int and the other is of type double. (b) Which of the following are advantages of using StdIn instead of command-line arguments? Mark each statement as either advantage or not advantage. advantage not advantage O You can enter input data while your program is executing. You can execute your program using different input data without having to recompile it. Your program can process the input data in reverse order. Your program can process huge amounts of input data more than can be stored in memory at any one time.
Expert Answer:
Answer rating: 100% (QA)
1 Java expressions Lets evaluate the given Java expressions using the provided variable values int x 2 int y 3 int z 4 x evaluates to 2 z yy x can be evaluated step by step yy evaluates to 1 integer d... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Determine the difference quotient f(x) = 6-7x - f(x + h) f(x) h
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Question 1 Which of the following is NOT a relational operator in Java? <> <= == > 1 points Question 2 Which of the following is not alogical operator? ! || != && 1 points...
-
Suppose that, in a Brazilian municipality, theprobability that a randomly selected resident likessoccer is 1/4, while the probability that he likes soap operas is1/2. Determine the probability that 1...
-
Determine the internal normal force, shear force, and moment at point C in the simply supported beam. Point C is located just to the right of the 1500-lb ? ft couple moment. 500 Ib/ft 30 1500 lb ft...
-
Rory invested a total of $7800 in shares of ABC Ltd. and XYZ Inc. One year later the investment was worth $9310, after the shares of ABC had increased in value by 15% and the shares of XYZ were up...
-
Why are some archaea described as extremophiles?
-
Green Lighting Supply plans inventory levels (at cost) at the end of each month as follows: May, $271,000; June, $226,000; July, $209,000; and August, $241,000. Sales are expected to be June,...
-
A data analyst at a manufacturing company records the results of inventory counts. For each inventory item, they indicate whether it is present or not. What data type is being collected in this...
-
Visit the website for the Congressional Budget Office (www.cbo.gov), follow the link to Budget and Economic Information, and look up the most current Monthly Budget Review. What is the CBOs estimate...
-
A Company purchased a drill press priced at $170,000 in year 0. The company additionally incurred $30,000 for site preparation and labor to install the machine. The drill press was classified as a...
-
Because the nation's inflation rate over the longer run is primarily determined by monetary policy, the Federal Reserve can work directly to ensure that the U.S. economy benefits from low and stable...
-
Indexing Social Security benefits to automatically and annually adjust to compensate for the erosion in their value due to inflation was a strategy used by both political parties to garner support...
-
Walter considered himself a failure because he has been unemployed for almost a year. However, Walter read an article that explained that unemployment in his area has been on the rise over the last...
-
Amy invested in three companies: 1700 dollars for Apple, 2200 dollars for Google and 1100 dollars for Starbucks. Over the course of one year, she found that Apple went down 2 percent, Google went up...
-
A possible logarithmic model for the data is y=2.6+2.2log x . Use this model to determine the y-value when x = 1.25. Round your answer to the tenths place.
-
Merino Corp. has requested a new line of credit to address the seasonality of revenues. The request is for an $6,250,000 demand loan and resulted in your lender requiring a working capital analysis....
-
You purchase a bond with a coupon rate of 6.7 percent, a par value $1,000, and a clean price of $905. Assume a par value of $1,000. If the next semiannual coupon payment is due in two months, what is...
-
(a) Nonpolar aromatic compounds were separated by HPLC on an octadecyl (C18) bonded phase. The eluent was 65 vol% methanol in water. How would the retention times be affected if 90% methanol were...
-
Use the method in Box 9-2 to find the pH and concentration of HA- in a 0.01 F solution of the amphiprotic salt Na+ HA- derived from the diprotic acid H2A with pK1 = 4 and (a) pK2 = 8 or (b) pK2 = 5.
-
A solution was prepared by dissolving 0.1947 g of HgO (Table 10-4) in 20 mL of water containing 4 g of KBr. Titration with HCl required 17.98 mL to reach a phenolphthalein end point. Calculate the...
-
Consider a sequence of random variables \(\left\{X_{n}ight\}_{n=1}^{\infty}\) where \(X_{n}\) has probability distribution function \[f_{n}(x)= \begin{cases}{[\log (n+1)]^{-1}} & x=n \\ 1-[\log...
-
Suppose that \(\left\{X_{n}ight\}_{n=1}^{\infty}\) is a sequence of independent random variables from a common distribution that has mean \(\mu\) and variance \(\sigma^{2}\), such that...
-
Let \(\left\{X_{n}ight\}_{n=1}^{\infty}\) be a sequence of random variables such that \[E\left(\sup _{n \in \mathbb{N}}\left|X_{n}ight|ight)
Study smarter with the SolutionInn App