Question

In: Computer Science

2. Will the following statements cause any error? (Yes/No) If a statement causes an error, what...

2. Will the following statements cause any error? (Yes/No) If a statement causes an error, what type of errors it is? (logic error, syntax/compile error, or runtime error). Again, there is no need to do the java code and test in jGrasp. You don’t need to provide the error message from the compiling or running results. The types of the error will be enough.

a. byte temp = 850;

b. celsius = 5 / 9 * (fahrenheit – 32);

c. int x = 3 / 0;

d. int y = 7 / 3.0;

e. int z = (int) 2.34567;

f. int value = 2147483647 + 1;

Solutions

Expert Solution

/*
a. byte temp = 850;
Solution:->
        Compile time error. Since 850 is a int type and
        incompatible with byte type.

b. celsius = 5 / 9 * (fahrenheit – 32);
Solution:-> It is logical compile time error.
    since celsius and fahrenheit is not declared any anywhere
    in the program

c. int x = 3 / 0;
Solution:-->Run time error. Since it is a correct syntax so no compile time
error. but you are dividing by zero. So a run time error occurs

d. int y = 7 / 3.0;
Solution: -->It is compile time error. Since you are assigning a
float value to int type. Which is not possible otherwise you need
to cast it before assigning.

e. int z = (int) 2.34567;
   Solution :--> Logical error, Since there is a loss of data. You are
   assigning a float to int which result is 2

f. int value = 2147483647 + 1;

Solution :--> Logical error, Since int is now out of its range ,
int range in java is -2,147,483,648 to 2,147,483, 647. So after adding 1
it goes to negative side and result is -2147483648.

 */
//If you need any help regarding this solution .......... please leave a comment ...... thanks

Related Solutions

What is the output produced by each statement below? If the statement causes an error, comment...
What is the output produced by each statement below? If the statement causes an error, comment it out and write either "compiler error" or "runtime error" as appropriate. For each line make your guess and then move the open comment down a line to test your theory. public class Main { public static void main(String[] args) { First var1 = new Second(); First var2 = new Third(); First var3 = new Fourth(); Second var4 = new Third(); Object var5 =...
Each of the following statements contains an error. Describe each error and explain why the statement...
Each of the following statements contains an error. Describe each error and explain why the statement is wrong. (a) If the residuals are all negative, this implies that there is a negative relationship between the response variable and the explanatory variable. (b) A strong negative relationship does not imply that there is an association between the explanatory variable and the response variable. (c) A lurking variable is always something that can be measured.
1. What are the causes of the common cold? 2. How does a virus cause a...
1. What are the causes of the common cold? 2. How does a virus cause a disease?
1. According to Van Den Bos and colleagues (2011), a medical error is: 2. What causes...
1. According to Van Den Bos and colleagues (2011), a medical error is: 2. What causes these errors? Keers and colleagues conducted an extensive literature review of qualitative and quantitative studies of causes of medication administration errors (MAEs) in hospital settings. They found:
Identify which of the following statements will generate an error. If there is an error, which...
Identify which of the following statements will generate an error. If there is an error, which phase of compiler construction (if any) will be suitable to detect the following errors and why? 1. A function is defined with the same signature as the previous one. 2. A variable named ‘new’ is defined and initialized two times. Once in main function and second in a “for” loop inside main function. 3. A multi-line comment that starts but not ends. 4. The...
What are potential causes of hypoxia that could cause the CVA?
What are potential causes of hypoxia that could cause the CVA?
If a switch statement contains no break statements at all, a. a syntax error will occur...
If a switch statement contains no break statements at all, a. a syntax error will occur b. each of the case clauses will be executed every time the switch statement is encountered c. this is equivalent to having the switch statement always take the default clause, if one is present d. this is not a syntax error but nothing within the switch statement will ever be executed e. None of these Which one of these options?
HEART ATTACK 1. AN OVERVIEW OF THE ILLNESS/CONDITION. AT MINIMUM INCLUDE ANY USUAL CAUSE OR CAUSES...
HEART ATTACK 1. AN OVERVIEW OF THE ILLNESS/CONDITION. AT MINIMUM INCLUDE ANY USUAL CAUSE OR CAUSES ORGANS AFFECTED USUAL SYMPTOMS AND COMPLICATIONS ADDITIONAL COMORBID CONDITIONS TO WATCH FOR, IF ANY ANY ADDITIONAL AND IMPORTANT INFORMATION TO KEEP IN MIND WHEN DEALING WITH A PATIENT WITH THE ILLNESS/CONDITION 2. WHAT WOULD BE THE TYPICAL TREATMENTS THAT WOULD BE CONSIDERED FOR THE CONDITION.
Are the following statements true or false? 1. Let P(n) be the statement "If any string...
Are the following statements true or false? 1. Let P(n) be the statement "If any string of length n over {a, b} has more a's than b's, then it has two a's in a row". We can prove this statement is true for all n with n ≥ 2 by proving P(2), P(3), and "for all n: P(n) → P(n+2)". 2. Let P(x) be a predicate with one free variable x of type natural. If I prove P(0), "for all...
2. (a) For each of the following statements, indicate whether it is a positive statement or...
2. (a) For each of the following statements, indicate whether it is a positive statement or a normative statement and why. 4 marks i. A fundamental assumption of the economic theory of consumer behavior is that consumers always prefer having more of any good to having less of it. ii. Provincial governments should not subsidize private corporations by training welfare recipients. iii. To make the good available to more people, a lower price should be set. iv. When the price...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT