Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Is it ok to compare two array references? For instance, suppose we have array x and array y, is it ok to do
1. Is it ok to compare two array references? For instance, suppose we have array x and array y, is it ok to do "if(x == y)"? Why or why not? (4 pts) 2. Consider the code below and answer questions (4 pts). int a[ ] = new int[10]; int b[] = new int[10]; for(int index = 0; index < 10; ++index) a[index] = b[index] = index; 2.1) True or False: all elements in array a have same values as elements in array b. 2.2) True or False: expression (x==y) returns true because these two arrays are equal. 3. (5pts) Given array x with declaration (int x[] = new int[100];), answer questions below: 3.1) how to access the value of the first array element? Write down your expression. 3.2) how to access the value of the last array element? Write down your expression. 3.3) how to print values of all array elements one by one? Write down your code. 4. (8pts) Consider the methods below and answer questions (each method is independent). public static XYZ(int a, int b) { return a+b; 4.1) 4.2) } Is this method correct or not? If not, how to make it right? 4.4) public static void ABC() { System.out.println("This is method ABC"); return 0; } Is this method correct or not? If not, how to make it right? 4.3) public static void WWW(int a, int b) { if(a > b) else System.out.println(a + "is bigger"); System.out.println(b + "is bigger"); } Is this method correct or not? If not, how to make it right? public static double calculateAREA(int x) { double pi = 3.14; double area = pi * x * x; return; } Is this method correct or not? If not, how to make it right?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
1 It is not okay to compare two array references using the equality operator This is because compare...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started