1.Following code will result in: int num = 5/0; Compilation error: Divisions mus
ID: 3909754 • Letter: 1
Question
1.Following code will result in: int num = 5/0;
Compilation error: Divisions must be in a try block
2. Assume a, b, and c have been defined to be integer variables. Which of the following values make the expression !(a == b) && (c > a) true?
a = 10, b = 20, c = 10
3.The scope of the parameter is limited to the method which calls it.
False
4.What is printed by the following code fragment?
int[] a = {0,1,2,3,4,5,6};
System.out.println(a.length);
Can't tell. There is not enough information
5.You want to initialize all of the elements of a double array a to the same value equal to 1.5.
What could you write?
.Assume that the array has been correctly initialized)
for (int i=0; i<a.length+1; i++) a[i] = 1.5;
6.Consider the method castToIntArray that has an array of double type as a formal parameter and returns an array of integers. What is the signature of the method?
a Runtime Exception: DivideByZeroExceptionExplanation / Answer
1.
int num = 5/0;
Runtime Exception: DivideByZeroException.
Option a
2.
a = 10, b = 20, c = 15
a, b, and c have been defined to be integer variables. Which of the following values make the expression !(a == b) && (c > a) true
!(a == b) means (a!=b)
a = 10, b = 20, c = 15
10!=20 ->True
(15 > 10) ->True
!(a == b) && (c > a) // True and True so it is true
Option c
3.
The scope of the parameter is limited to the method which calls it.
True
4.
int[] a = {0,1,2,3,4,5,6}; // The number of elemnts is 7
System.out.println(a.length); // It print 7
Option b
5.
Initialize all of the elements of a double array a to the same value equal to 1.5.
for(int i=0; i<a.length; i++) // Loop runs from 0 array length
a[i] = 1.5; // Initialize all elements 1.5
Option c
6.
Consider the method castToIntArray that has an array of double type as a formal parameter and returns an array of integers. What is the signature of the method
public int[] castToIntArray(double[] a)
Option e
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.