-
public static void main(String[] args ){
int x = 2, y = 3, z = 0;
System.out.print( "x = " + x + "y = " + y + "z = " + z);
z = p(y,x);
System.out.print( "x = " + x + "y = " + y + "z = " + z);
}
public static int p (int z, int y ){
int x = z;
return x - y;
}
-
public static void main(String[] args ){
int x = 2, y = 3, z = 0;
x = p(x,y);
System.out.print( "x = " + x + "y = " + y + "z = " + z);
y = p(x,y);
System.out.print( "x = " + x + "y = " + y + "z = " + z);
}
public static int p (int x, int z ){
int y = z;
return x - z;
}
-
public static void main(String[] args ){
int x = 2, y = 3;
x = p(x,y);
x = p(y,x);
x = p(x,y);
System.out.print( "x = " + x + "y = " + y);
}
public static int p (int y, int x){
return 2 * x + y;
}
-
public static void main(String[] args ){
int x = 2, y = 3, z = 0;
funcA (x, z);
System.out.print("INSIDE MAIN");
System.out.print( "x = " + x + "y = " + y + "z = " + z);
}
public static void funcA (int x, int y){
int z = x;
System.out.print("INSIDE DISPLAY");
System.out.print( "x = " + x + "y = " + y + "z = " + z);
}
-
What does the array nums contain after executing the following instructions?
int [] nums = {1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12};
nums[0] = nums[10 - 1];
nums[10 - 3] = 7;
-
What does the array nums contain after executing the following instructions?
int [] nums = {5, 10, 15, 20, 25, 30, 35};
int i = 4;
nums[i] = nums[i + 1];
-
What does the array nums contain after executing the following segment of code?
int [] nums = {2, 3, 5, 1, 8, 4, 9, -3, 6, 3};
for (int i = 0; i < nums.length; i++){
nums[i] = nums[i] + 1;
}
-
What does the array nums contain after executing the following segment of code?
int [] nums = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
for (int i = 0; i < nums.length - 2; i++){
nums[i] = nums[i + 1];
}
-
What output is produced after executing the following segment of code?
NOTE: Arrays.toString(arr) is an easy way to display the contents of an integer array.
public static void main(String[] args) {
int[] arr = { 1, 2, 3 };
System.out.println(Arrays.toString(arr));
arr = func(arr);
System.out.println(Arrays.toString(arr));
}
public static int [] func(int[] arr) {
int [] brr = new int [arr.length*2];
int j = 0;
for (int i = 0; i < arr.length; i++){
brr[j] = arr[i];
j++;
brr[j] = arr[i];
j++;
}
return brr;
}