Line 1: 4 Line 2: 6 Line 3: 3 Line 4: 2 Line 5: 1 Line 6: 7 Line 7: 9 Line 8: 3
What is the result in each of the lines below? LinkedList« Integer» list = new LinkedList<Integer»...
1: import java.util.*; 2: class Test 3: { 4: public static void main(String[] args) 5: { 6: ArrayList<Object> list = new ArrayList<Object>(); 7: list.add("First Element"); 8: list.add(new Integer(12)); 9: String str = (String) list.get(0); 10: String str2 = (String)list.get(1); 11: } 12: } There is a run time error on which line number? A) Line 9 B) Line 7 C) No errors D) Line 8 E) Line 10 in Java
Write the output produced when the following method is passed each of the following lists and give the formal code for the problem: public static void mystery1(ArrayList<Integer> list) { for (int i = list.size() - 1; i > 0; i--) { if (list.get(i) < list.get(i - 1)) { int element = list.get(i); list.remove(i); list.add(0, element); } } System.out.println(list); } a. [2, 6, 1, 8] b. [30, 20, 10, 60, 50, 40]
Create a new Java Application that test MyStack by having the following methods in main class: 1. A method to generate a number of element between two given values and save them in a stack 2. A method to print a stack (10 elements per line). The original stack should remain as is after the print 3. A method to exchange the first element and the last element in a stack 4. A Boolean method to search for a value...
Please use Java programming: Modify both ArrayList and LinkedList classes and add the following method to both classes: public void reverseThisList(), This method will reverse the lists. When testing the method: print out the original list, call the new method, then print out the list again ------------------------------------------------------------------------- //ARRAY LIST class: public class ArrayList<E> implements List<E> { /** Array of elements in this List. */ private E[] data; /** Number of elements currently in this List. */ private int size; /**...
[Java] Please test your code in the link I provide
before you post your answer.
The output should be looked like exact same as the
tester.
http://www.codecheck.it/files/17033122188mcxvjz8n8qbk0k9fyfrd3w95
Use the following file:
LinkedListUtilTester.java
import java.util.LinkedList;
public class LinkedListUtilTester
{
public static void main(String[] args)
{
LinkedList<String> list = new LinkedList<>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.add("5");
list.add("6");
list.add("7");
list.add("8");
list.add("9");
list.add("10");
list.add("11");
list.add("12");
list.add("13");
list.add("14");
list.add("15");
LinkedListUtil.shrink(list, 3);
System.out.println(list);
System.out.println("Expected: [1, 2, 4, 5, 7, 8, 10, 11, 13, 14]");
System.out.println(LinkedListUtil.reverse(list));
System.out.println("Expected:...
Please answer the question in the picture below and explain your
answer. If it helps, the associated coursework is taught in
Java.
12. Given the following method, Write the output when the following method is passed each of the following lists: public static void mystery (ArrayList<Integer> list) { for (int i = 0; i < list.size()-1; i++) { int e = list.get(i); list.add (i+2, e + 3); list.remove(i); System.out.println(list); a. [80,60,50,40,30] b. (5,5,5,5,3]
NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT WOULD CAUSE THE HW1.java TO PRINT THE RIGHT DATA.!!! The LinkedList class implements both the List interface and the Stack interface, but several methods (listed below) are missing bodies. Write the code so it works correctly. You should submit one file, LinkedList.java. Do not change the interfaces. Do not change the public method headers. Do not rename the LinkedList class. None of your methods...
Look for some finshing touches java help with this program. I just two more things added to this code. A loop at the end that will ask the user if they want to quit if they do want to quit the program stops if they don't it loads a new number sequence. import java.util.Random; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.List; import java.util.Collections; public class main { public static void main(String[] args) { List < Sequence > list =...
using: class MyQueue<T> { private java.util.LinkedList<T> list; public MyQueue() { list = new java.util.LinkedList<T>(); } public void enqueue(T data) { list.add(data); } public T dequeue() { return list.remove(0); } public T peek() { return list.get(0); } public int size() { return list.size(); } public boolean isEmpty() { return list.isEmpty(); } } class MyQueueTest { public static void main(String[] args) { MyQueue<Integer> queue = new MyQueue<Integer>(); queue.enqueue(3); queue.enqueue(2); queue.enqueue(7); queue.enqueue(1); while (!queue.isEmpty()) { System.out.println(queue.dequeue()); } } } please solve the following:...
Please answer question 8
Given the following method, what is the result of a call to System.out.println(foo(list)) if list contains { 1, 1, 2, 2 )? public Integer foo( IndexedunorderedList<Integer> list ) Integer bar = new Integer (0); 0; X < list.size(); x++) bar += list.get(x) * list.get (x); return bar; 30 is printed to the console 14 is printed to the console 10 is printed to the console Code throws an IndexOutOfBoundException QUESTION 8 What is the runtime of...