Question 14 1 pts The following bit of code is attempting to find the x-coordina
ID: 3838647 • Letter: Q
Question
Question 14 1 pts
The following bit of code is attempting to find the x-coordinate of the Point that is farthest to the right in the x-y plane in the array 'points'. One line contains an error. Which line is it?
Point[] points = ... // Assume the array has been filled with Point object references
...
double xMax = points[0].getX(); // line 1
for ( int i = 1; i < points.length; i++ ) { // line 2
if ( points[i].getX() > xMax ) { // line 3
xMax = points[i]; // line 4
}
}
Flag this Question
Question 15 1 pts
The last 3 lines in the following program are supposed to swap the two elements in the array 'blooms' identified by the index values 'mary' and 'john'. Choose from among the answers listed the correct statement for the middle of these 3 lines:
Flower[] blooms = ... // Assume this array is filled with object references
int mary, john; // Assume these variables have values assigned to them
...
Flower temp = blooms[mary];
// What statement goes here??
blooms[john] = temp;
Flag this Question
Question 16 1 pts
The following statement constructs a new String array. What initial value is stored in each of the array elements?
String[] words = new String[8];
Flag this Question
Question 17 1 pts
What is printed out by the following short program?
double[] x1 = {3.3, 4.4, 5.5, 6.6};
double[] x2 = x1;
x2[1] = 24.0;
double x = x1[1] * 2;
System.out.println(x1[1]);
Flag this Question
Question 18 1 pts
Consider this code:
String[] names = {"Mary", "Jose", "Minh"};
System.out.println(names[1]);
What is the data type of names[1]?
Flag this Question
Question 19 1 pts
[This is different than the previous question.] Consider this code:
String[] names = {"Mary", "Jose", "Minh"};
System.out.println(names[1]);
What is the data type of names?
Flag this Question
Question 20 1 pts
What will be printed by the following program?
int[] nums1 = {7, 6, 5, 4};
int[] nums2 = {7, 6, 5, 4};
boolean ans1 = (nums1 == nums2);
boolean ans2 = nums1.equals(nums2);
boolean ans3 = Arrays.equals(nums1, nums2);
System.out.println( ans1 + "-" + ans2 + "-" + ans3 );
Explanation / Answer
Point[] points = ... // Assume the array has been filled with Point object references
...
double xMax = points[0].getX(); // line 1
for ( int i = 1; i < points.length; i++ ) { // line 2
if ( points[i].getX() > xMax ) { // line 3
xMax = points[i]; // line 4
}
}
ans:line 2
=============================================
Question 15
ans : blooms[mary] = blooms[john];
when mary values goes into temp then blooms[mary] is null, so assigning blooms[john] to blooms[mary]
then value of tem assign to blooms[john] values will be swap.
==============================================================
Question 16.
ans: initial value is stored in each of the array elements is null
the value null.
===========================================================
Question 17.
ans:What is printed out by the following short program?
double[] x1 = {3.3, 4.4, 5.5, 6.6};
double[] x2 = x1;
x2[1] = 24.0;
double x = x1[1] * 2;
System.out.println(x1[1]);
output is 24.0
===========================================================
Question 18 1 pts
Consider this code:
String[] names = {"Mary", "Jose", "Minh"};
System.out.println(names[1]);
What is the data type of names[1]?
ans: string
======================================================
Question 19 1 pts
[This is different than the previous question.] Consider this code:
String[] names = {"Mary", "Jose", "Minh"};
System.out.println(names[1]);
What is the data type of names?
ans :String[]
================================================
Question 20 1 pts
What will be printed by the following program?
int[] nums1 = {7, 6, 5, 4};
int[] nums2 = {7, 6, 5, 4};
boolean ans1 = (nums1 == nums2);
boolean ans2 = nums1.equals(nums2);
boolean ans3 = Arrays.equals(nums1, nums2);
System.out.println( ans1 + "-" + ans2 + "-" + ans3 );
ans:false - false - true
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.