Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6) The following statement constructs a new String array. What initial value is

ID: 3837429 • Letter: 6

Question

6) The following statement constructs a new String array. What initial value is stored in each of the array elements?

String[] words = new String[8];

7) 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]);

8) Consider this code:

String[] names = {"Mary", "Jose", "Minh"};
System.out.println(names[1]);

What is the data type of names[1]?

9) [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?

10) 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 );

a) the empty String ( "" )

Explanation / Answer

6ans)option :d
because for any string variable the initial value it stores is null
for short the default value sets to zero
for int the default value is set to zero
for long the default value is set to zero
for float the default value is initiaized to o.of
for boolean the default value is set to false.

7ans)option e:
24.0
because we assing x2=x1;
so what ever the x1 values x2 values are same
in third step we assing 2nd element as 24.0
2nd statement ..gives you solution ..so if we assing x2[3]=7.7
then the 4th element in x2 is 7.7
and aslo 4th element in x1 is 7.7



8ans)output is :Jose
becase the array index starts at zero ..
here names[i] gives you second element in names array.
data type of name[1] is String..

9ans)here the data type of names is String[]
because previously the questio is about single element so it is string..now the question is about the entire array..so this String array..


10ans)option c:false false true
ans1 is returns false .if it boolean ans=(num1!=num2) then it returns true
ans2 is also false
ans 3 is valid statements we use inbulit array class and we call equals method in that gives you true because both elements in arrays are equal

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote