Question 2 If I wanted to iterate through a basic Java array, how would I do...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 2 If I wanted to iterate through a basic Java array, how would I do it? Would I use the "length" property or the "size()" method? For basic arrays, use the "length" property. int[] array (1, 2, 3, 4, 5}; for(int i = 0; i < array.length; i++) { System.out.println(array[i]); } For basic arrays, use the ".size()" method. int[] array (1, 2, 3, 4, 5}; for(int i = 0; i <array.size(); i++) { System.out.println(array[1]); } 1 pts E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero 2022 Fall Semester Home Announcements 38 Syllabus Modules Grades People Tutoring Resources Question 3 1 pts If I wanted to iterate through Java's ArrayList, how would I do it? Would I use the "length" property or the ".size()" method? For Java's ArrayList, I would use the "length" property. ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5)); for(int i = 0; i < arrayList.length; i++) { System.out.println(arrayList.get(i)); K 69°F Mostly cloudy } For Java's ArrayList, I would use its ".size()" method. ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5)); for(int i = 0; i < arrayList.size(); i++) { System.out.println(arrayList.get(i)); } Question 4 1 pts OneDrive Screenshot saved The screenshot was added to your OneDrive. 4:59 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud 38 K 2022 Fall Semester Home Announcements Syllabus Modules byu chat page Course Hero TestOut LabSim ArrayList<integer> arrayList = new ArrayList<integer>(Arrays.asList(1, 2, 3, 4, ɔ)); for(int i = 0; i < arrayList.size(); i++) { System.out.println(arrayList.get(i)); } Question 4 1 pts Grades People Tutoring Resources True or False: I would use Java's basic array when I know the size of the data or the array will not change, and I should use Java's ArrayList when I need a dynamic array and I don't know how much data may or may not be added. 69°F Mostly cloudy True O False Question 5 1 pts OneDrive What will happen if I try the to access an element in a basic array at the index of -1, like so: Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero 38 2022 Fall Semester Home Announcements Syllabus Question 5 1 pts What will happen if I try the to access an element in a basic array at the index of -1, like Modules so: Grades People Tutoring Resources int[] array = {1, 2, 3, 4, 5}; int test = array[-1]; K 69°F Mostly cloudy ☐ Because there is no negative index of an array, it will simply return the first element, or the element at index 0 It will throw an Array Index Out Of Bounds Exception. Because there is no negative index, it will wrap around to the back of the array to the last element, or index 4 in this case. Question 6 What will the following code print? ୪ OneDrive 1 pts Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero 2022 Fall Semester Home Announcements 38 Syllabus Modules K Question 6 1 pts Grades People Tutoring Resources What will the following code print? int[] array = {2, 4, 6, 8, 10}; int test = array[5]; System.out.println(test); It will throw an exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of boun ds for length 5 69°F Mostly cloudy It will print the last element: 10 Question 7 ୪ 2 pts OneDrive Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage ← → C⭑ LDS D 38 K Quiz: 8.3 Quiz (30 min.) + ensign.instructure.com/courses/14050/quizzes/186729/take FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester iCloud byu chat page TestOut LabSim Course Hero Question 7 2 pts Home Announcements The code below prints out something like this: Syllabus Modules [I@626b2d4a [1, 2, 3, 4, 5] Grades People Tutoring Resources Why does printing a basic Java array print something that seems random while Java's ArrayList prints the data in the array in a readable way? public static void main(String[] args) { } int[] array = {1, 2, 3, 4, 5}; ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5)); System.out.println(array); System.out.println(arrayList); 69°F Mostly cloudy This is an error coming from the IDE. The IDE should print the data in the integer array in a readable way. ○ Java's ArrayList is an object, and has been given the functionality to print a readable String. Java's basic array is not an object, and printing it simply prints a reference of the memory location of the array. Java's arrays don't work properly, so you should always use an ArrayList. OneDrive > Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page 38 K 2022 Fall Semester Home Announcements Syllabus Modules TestOut LabSim Course Hero Java's arrays don't work properly, so you should always use an ArrayList. Question 8 2 pts Grades People Tutoring Resources What is printed in the following code? (HINT: I am not passing a primitive type, but an ArrayList.) public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<<Integer>(); System.out.println(list); add5Numbers(list); System.out.println(list); 69°F Mostly cloudy } public static void add 5Numbers (ArrayList<Integer> list) { list.add(1); } list.add(2); list.add(3); list.add(4); list.add(5); System.out.println(list); [] [1, 2, 3, 4, 5] [ ] ୪ 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero list.add(4); list.add(5); 2022 Fall Semester System.out.println(list); } 38 Home Announcements Syllabus Modules [ ] [1, 2, 3, 4, 5] [ ] Grades People Tutoring Resources [] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [ ] [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] [1, 2, 3, 4, 5] K 69°F Mostly cloudy о [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] ୪ OneDrive Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage ← → C D LDS Quiz: 8.3 Quiz (30 min.) + ensign.instructure.com/courses/14050/quizzes/186729/take FAFSA Student Loan ck Credit Karma M Gmail 25 iCloud byu chat page TestOut LabSim Course Hero 2022 Fall Semester Home Announcements 8.3 Quiz (30 min.) Started: Oct 31 at 3:59pm Quiz Instructions дв Syllabus Modules K Grades People Tutoring Resources 69°F Mostly cloudy Question 1 If I wanted to print the first element in an array, how would I do it? int[] array = {1, 2, 3, 4, 5}; System.out.println(array[1]); int[] array = {1, 2, 3, 4, 5}; System.out.println(array[0]); Question 2 1 pts 1 pts حمد ما Questions Question 1 Question 2 Question 3 Question 4 Question 5 Question 6 Question 7 Question 8 Time Elapsed: Hide Time Attempt due: Nov 5 at 10pm 0 Minutes, 12 Seconds 4:59 PM 10/31/2022 Question 2 If I wanted to iterate through a basic Java array, how would I do it? Would I use the "length" property or the "size()" method? For basic arrays, use the "length" property. int[] array (1, 2, 3, 4, 5}; for(int i = 0; i < array.length; i++) { System.out.println(array[i]); } For basic arrays, use the ".size()" method. int[] array (1, 2, 3, 4, 5}; for(int i = 0; i <array.size(); i++) { System.out.println(array[1]); } 1 pts E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero 2022 Fall Semester Home Announcements 38 Syllabus Modules Grades People Tutoring Resources Question 3 1 pts If I wanted to iterate through Java's ArrayList, how would I do it? Would I use the "length" property or the ".size()" method? For Java's ArrayList, I would use the "length" property. ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5)); for(int i = 0; i < arrayList.length; i++) { System.out.println(arrayList.get(i)); K 69°F Mostly cloudy } For Java's ArrayList, I would use its ".size()" method. ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5)); for(int i = 0; i < arrayList.size(); i++) { System.out.println(arrayList.get(i)); } Question 4 1 pts OneDrive Screenshot saved The screenshot was added to your OneDrive. 4:59 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud 38 K 2022 Fall Semester Home Announcements Syllabus Modules byu chat page Course Hero TestOut LabSim ArrayList<integer> arrayList = new ArrayList<integer>(Arrays.asList(1, 2, 3, 4, ɔ)); for(int i = 0; i < arrayList.size(); i++) { System.out.println(arrayList.get(i)); } Question 4 1 pts Grades People Tutoring Resources True or False: I would use Java's basic array when I know the size of the data or the array will not change, and I should use Java's ArrayList when I need a dynamic array and I don't know how much data may or may not be added. 69°F Mostly cloudy True O False Question 5 1 pts OneDrive What will happen if I try the to access an element in a basic array at the index of -1, like so: Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero 38 2022 Fall Semester Home Announcements Syllabus Question 5 1 pts What will happen if I try the to access an element in a basic array at the index of -1, like Modules so: Grades People Tutoring Resources int[] array = {1, 2, 3, 4, 5}; int test = array[-1]; K 69°F Mostly cloudy ☐ Because there is no negative index of an array, it will simply return the first element, or the element at index 0 It will throw an Array Index Out Of Bounds Exception. Because there is no negative index, it will wrap around to the back of the array to the last element, or index 4 in this case. Question 6 What will the following code print? ୪ OneDrive 1 pts Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero 2022 Fall Semester Home Announcements 38 Syllabus Modules K Question 6 1 pts Grades People Tutoring Resources What will the following code print? int[] array = {2, 4, 6, 8, 10}; int test = array[5]; System.out.println(test); It will throw an exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of boun ds for length 5 69°F Mostly cloudy It will print the last element: 10 Question 7 ୪ 2 pts OneDrive Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage ← → C⭑ LDS D 38 K Quiz: 8.3 Quiz (30 min.) + ensign.instructure.com/courses/14050/quizzes/186729/take FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester iCloud byu chat page TestOut LabSim Course Hero Question 7 2 pts Home Announcements The code below prints out something like this: Syllabus Modules [I@626b2d4a [1, 2, 3, 4, 5] Grades People Tutoring Resources Why does printing a basic Java array print something that seems random while Java's ArrayList prints the data in the array in a readable way? public static void main(String[] args) { } int[] array = {1, 2, 3, 4, 5}; ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5)); System.out.println(array); System.out.println(arrayList); 69°F Mostly cloudy This is an error coming from the IDE. The IDE should print the data in the integer array in a readable way. ○ Java's ArrayList is an object, and has been given the functionality to print a readable String. Java's basic array is not an object, and printing it simply prints a reference of the memory location of the array. Java's arrays don't work properly, so you should always use an ArrayList. OneDrive > Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page 38 K 2022 Fall Semester Home Announcements Syllabus Modules TestOut LabSim Course Hero Java's arrays don't work properly, so you should always use an ArrayList. Question 8 2 pts Grades People Tutoring Resources What is printed in the following code? (HINT: I am not passing a primitive type, but an ArrayList.) public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<<Integer>(); System.out.println(list); add5Numbers(list); System.out.println(list); 69°F Mostly cloudy } public static void add 5Numbers (ArrayList<Integer> list) { list.add(1); } list.add(2); list.add(3); list.add(4); list.add(5); System.out.println(list); [] [1, 2, 3, 4, 5] [ ] ୪ 5:00 PM 10/31/2022 E Ensign Homepage Quiz: 8.3 Quiz (30 min.) + ← → C⭑ ensign.instructure.com/courses/14050/quizzes/186729/take LDS FAFSA Student Loan ck Credit Karma M Gmail iCloud byu chat page TestOut LabSim Course Hero list.add(4); list.add(5); 2022 Fall Semester System.out.println(list); } 38 Home Announcements Syllabus Modules [ ] [1, 2, 3, 4, 5] [ ] Grades People Tutoring Resources [] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [ ] [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] [1, 2, 3, 4, 5] K 69°F Mostly cloudy о [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] ୪ OneDrive Screenshot saved The screenshot was added to your OneDrive. 5:00 PM 10/31/2022 E Ensign Homepage ← → C D LDS Quiz: 8.3 Quiz (30 min.) + ensign.instructure.com/courses/14050/quizzes/186729/take FAFSA Student Loan ck Credit Karma M Gmail 25 iCloud byu chat page TestOut LabSim Course Hero 2022 Fall Semester Home Announcements 8.3 Quiz (30 min.) Started: Oct 31 at 3:59pm Quiz Instructions дв Syllabus Modules K Grades People Tutoring Resources 69°F Mostly cloudy Question 1 If I wanted to print the first element in an array, how would I do it? int[] array = {1, 2, 3, 4, 5}; System.out.println(array[1]); int[] array = {1, 2, 3, 4, 5}; System.out.println(array[0]); Question 2 1 pts 1 pts حمد ما Questions Question 1 Question 2 Question 3 Question 4 Question 5 Question 6 Question 7 Question 8 Time Elapsed: Hide Time Attempt due: Nov 5 at 10pm 0 Minutes, 12 Seconds 4:59 PM 10/31/2022
Expert Answer:
Answer rating: 100% (QA)
1 Correct Option is b Systemoutprintlnarray0 The first element of array is present at index 0 Hence ... View the full answer
Related Book For
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.
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Our thoughts return to Ambrose and his nuts and berries. Ambroses utility function is U(x1, x2) = 4x1 + x2, where x1 is his consumption of nuts and x2 is his consumption of berries. (a) Let us find...
-
The Tempura Spirits Company produces two products-methanol (wood alcohol) and turpentine-by a joint process. Joint costs amount to $124,000 per batch of output. Each batch totals 9,500 gallons: 25%...
-
Write an iterated integral for R dA over the described region R using (a) Vertical cross-sections, (b) Horizontal cross-sections. y = 8 J X
-
Copy your worksheet from Question 6 into another worksheet. Change the increase from 10% to 18%. Protect the worksheet, so that changes cannot be made. Question 6 Open a new spreadsheet. Type...
-
Dozier Industries Inc. manufactures only one product. For the year ended December 31, 2014, the contribution margin increased by $38,500 from the planned level of $1,386,000. The president of Dozier...
-
1. An object of mass of 4 kg is resting at a height of 2 m and then falls to the ground. a. Model the energy of the object-Earth system with Energy Bar Charts when at the initial height and ground...
-
The two particles of mass m and 2m, respectively, are connected by a rigid rod of negligible mass and slide with negligible friction in a circular path of radius r on the inside of the vertical...
-
In the summer of 2022, Suzy and Katie were preparing for their best friend Vera's bachelorette party. Although Suzy and Katie share Vera as their best friend respectively, the two do not always get...
-
For transaction four, the error message when the order exceeds the customer's credit limit is an example of what type of internal control? Explain.
-
Which industries can use standard costing systems? Explain
-
1.) If attitudes can be measured, what is the most important element that feeds into measuring attitudes? It may be easier to measure the attitude of someone you know well but when you have a big...
-
Dont Fall Down Incorporated produces skates and offers a one-year warranty on all products. During 2019, the company recorded net sales of $3,887.4 million. Historically, about 2% of all sales are...
-
Wildhorse Company exchanged equipment used in its manufacturing operations plus $3,240 in cash for similar equipment used in the operations of Sheffield Company. The following information pertains to...
-
1). Trifles Ltd acquired 280,000 shares in Bamburg Ltd on 01 July 2019 and as a result Trifles Ltd has a control of 80% in Bamburg. The purchased consideration transferred by Trifles Ltd in exchange...
-
2. Assume a person bends forward to lift a load "with his back" as shown in Figure P12.42a. The person's spine piv- ots mainly at the fifth lumbar vertebra, with the principal supporting force...
-
Compare and contrast the while and for iteration statements.
-
What does the following code segment do? for (int i = 1; i
-
The C# compiler always associates an else with the immediately preceding if unless told to do otherwise by the placement of braces ({ and }). This behavior can lead to what is referred to as the...
-
The relativity of simultaneity. Two clocks are placed at rest on the \(x^{\prime}\) axis of the primed frame, clock A at \(x^{\prime}=0\) and clock B at \(x^{\prime}=L_{0}\). They are therefore a...
-
A primed frame moves at \(V=(3 / 5) c\) relative to an unprimed frame. Just as their origins pass, clocks at the origins of both frames read zero, and a flashbulb explodes at that point. Later, the...
-
Synchronized clocks A and B are at rest in our frame of reference, a distance five light-minutes apart. Clock \(\mathrm{C}\) passes \(\mathrm{A}\) at speed (12/13) \(c\) bound for \(\mathrm{B}\),...
Arto Salomaa Mathematician Computer Scientist And Teacher 1st Edition - ISBN: 3030160483 - Free Book
Study smarter with the SolutionInn App