1. Is it ok to compare two array references? For instance, suppose we have array x...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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? 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. 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? 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?
Expert Answer:
Answer rating: 100% (QA)
1 It is not okay to compare two array references using the equality operator This is because compare... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
Solve Loe 4 (a) x (b) fo e-y/2 dy 8 X 1+x dx -6 1 ( c ) = = 14 dx (c) - 3 x -
-
Selected condensed information (in millions) for Investments R Us Company, a public company, follows for the year ended November 30, 2017. Income from investment in...
-
Is there a difference in the average number of years' seniority between returning part-time seasonal employees and returning full-time seasonal employees at a Vail Resorts' ski mountain? From a...
-
A hydrogen atom is excited from its ground state to the \(n=\) 4 state. The atom subsequently emits three photons, one of which has a wavelength of \(656 \mathrm{~nm}\). What are the wavelengths of...
-
Baker Co. is considering the following alternative financing plans: Income tax is estimated at 40% of income. Determine the earnings per share of common stock, assuming income before bond interest...
-
Plot the following 2-D diagram using MATLAB/OCTAVE command line/m-file Y (3 to 0 and 0 to 3) 2.5 N 1.5 1 0.5- Test image of your student ID> X (0 10 6)
-
Newton's second law is to position x(t) as Schroedinger's equation is to Select one: a. Probability, w*y O b. Momentum, pix.t) O c Wave function, 4(x.t) O d. Potential energy function, V(x.t)
-
The Alliance Corp. expects to sell the following number of units of copper cables at the prices indicated, under three different scenarios in the economy. The probability of each outcome is...
-
Question One: (10 Marks) Pertinent facts are given for a different individual in each of the Parts of this problem. For each Part, indicate whether or not this individual would be considered a...
-
1. Are risk and uncertainty the same or different? If they are different, explain the differences. 2. What are the four components of Risk Management and define each component. 3. What are the key...
-
Georgia is the sole shareholder of Andromeda Corporation, a calendar-year S corporation. Andromeda is indebted to Georgia in the amount of $5,000. For the current year, Andromeda earned $25,000 of...
-
Outline Psychodynamic Theory and how it relates to defense mechanisms (ie displaced, misplaced and overblown conflict and rationalization) ?
-
What is the need for filter paper which is used to stain the sample with Malachite Green?
-
Suppose that a flow network G = (V, E) violates the assumption that the network contains a path s t for all vertices V. Let u be a vertex for which there is no path s u t. Show that there must...
-
In this exercise we explore some technical aspects of general equilibrium theory in exchange economies and Robinson Crusoe economies. Unlike in other problems, parts A and B are applicable to both...
-
Fishing in the Commons: In the text, we introduced the notion of the Tragedy of the Commons and found its source in the emergence of externalities when property rights are not well established. This...
-
A. Suppose we begin in a system in which mortgage interest is not deductible and then tax deductibility of mortgage interest is introduced. (a) Using a graph (as you did in exercise 2.17) with square...
-
What is the advantage of being able to produce spores, as many bacteria do?
-
What is a chemoautotroph? What does a chemoautotroph have in common with a plant? How does a chemoautotroph differ from a plant in how it obtains food?
-
What is the difference between a heterotroph and an autotroph? Name a clade of living things that consists exclusively of heterotrophs and one that consists exclusively of autotrophs. Name a clade...
Study smarter with the SolutionInn App