What is the output of the following lines of code? int[] a = {3, 6, 9, 12, 15};
ID: 3634397 • Letter: W
Question
What is the output of the following lines of code?int[] a = {3, 6, 9, 12, 15};
int[] b = {3, 6, 9, 12, 15};
int[] c = b;
c[3] = 10;
System.out.println(a[3] + " " + b[3] + " " + c[3]);
After giving the output, explain briefly why it makes sense.
Fill in the blanks below to create a method that increments all of the elements of the array data by the amount incr. For example, if data refers to the array {1, 2, 3, 4, 5}, calling incrementAll(data, 2) should change the array to be {3, 4, 5, 6, 7}. Your code should work for an array of any length. You may assume that data is not null.
public static void incrementAll(int[] data, int incr) {
for (int i = ______; i < _____________; i++) {
_____________________;
}
}
Fill in the blanks below to create a method that looks through the array data and returns true if it contains one or more duplicate values (i.e., values that appear more than once), and returns false if there are no duplicate values -- i.e., if all of the values in the array are unique. For example, if you pass in the array {1, 4, 7, 4, 2}, the method should return true, because 4 appears more than once, whereas if you pass in the array {1, 4, 7, 5, 2}, the method should return false, because no value appears more than once. Your code should work for an array of any length. You may assume that data is not null. Hint: You will need nested loops.
public static ____________ hasDups(int[] data) {
for (__________; ___________; ________) {
// put one or more lines here
}
// You may or may not need one additional line here.
}
Explanation / Answer
please rate - thanks
What is the output of the following lines of code?
int[] a = {3, 6, 9, 12, 15};
int[] b = {3, 6, 9, 12, 15};
int[] c = b;
c[3] = 10;
System.out.println(a[3] + " " + b[3] + " " + c[3]); 12 10 10
After giving the output, explain briefly why it makes sense.
when you say int[]c=b you are saying b and c share the same memory, so when you change c[3] to 10 you are also changing b[3]
Fill in the blanks below to create a method that increments all of the elements of the array data by the amount incr. For example, if data refers to the array {1, 2, 3, 4, 5}, calling incrementAll(data, 2) should change the array to be {3, 4, 5, 6, 7}. Your code should work for an array of any length. You may assume that data is not null.
public static void incrementAll(int[] data, int incr) {
for (int i = _0_____; i < ___data.length__________; i++) {
________data[i]+=incr_____________;
}
}
Fill in the blanks below to create a method that looks through the array data and returns true if it contains one or more duplicate values (i.e., values that appear more than once), and returns false if there are no duplicate values -- i.e., if all of the values in the array are unique. For example, if you pass in the array {1, 4, 7, 4, 2}, the method should return true, because 4 appears more than once, whereas if you pass in the array {1, 4, 7, 5, 2}, the method should return false, because no value appears more than once. Your code should work for an array of any length. You may assume that data is not null. Hint: You will need nested loops.
public static ____boolean________ hasDups(int[] data) {
for (___int i=0_______; i < data.length-1______; i++________) {
// put one or more lines here
for(int j=i+1;j<data.length;j++)
if(data[i]==data[j])
return true;
}
// You may or may not need one additional line here.
return false;}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.