Question

Given 5. import java.util. 6. public class Sortof 7. public static void main(Stringl args) [ 8. ArrayList Integer> anew Array

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Option C:2,5,3,1.

Explanation:

First 1,5,3 is added to the list and then sorted: So the list contains 1,3,5 and then 2 is added. So the list contains 1,3,5,2. Then it is reversed, So the list contains 2,5,3,1.

Add a comment
Know the answer?
Add Answer to:
Given 5. import java.util. 6. public class Sortof 7. public static void main(Stringl args) [ 8. ArrayList Integer> anew ArrayList Integer 0 9. a.add(1); а.add(5); a.add(3); 11. Collections.sort(a)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. public class Threads5 { 2. public static void main (String[l args) 3. new Thread(new Runnable()...

    1. public class Threads5 { 2. public static void main (String[l args) 3. new Thread(new Runnable() 4. public void run() 5. System.out.print("bar"); 6. start(; 7 What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes normally and prints "bar". D. The code executes normally, but nothing prints

  • 1: import java.util.*; 2: class Test 3: { 4: public static void main(String[] args) 5: {...

    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

  • **JAVA*JAVA Question 1 How many k's values will be printed out? public static void main(Stringl args)...

    **JAVA*JAVA Question 1 How many k's values will be printed out? public static void main(Stringl args) for (int k-1: k10:k if (k8) continue: System.out.println k) Question 2 3.5 pts Analyze the following code. Which one is correct? package p public class A package p2: import p1. public class B extends Af int i- 5 private int j- 10: public A0I public static void main(Stringll args) B b new B0: System.out.println(a.i+", "+ajt", "+b.it""+bj): a.i is printable None of them b.i is...

  • import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {              ...

    import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {               int total = 0;               int num = 0;               File myFile = null;               Scanner inputFile = null;               myFile = new File("inFile.txt");               inputFile = new Scanner(myFile);               while (inputFile.hasNext()) {                      num = inputFile.nextInt();                      total += num;               }               System.out.println("The total value is " + total);        } } /* In the first program, the Scanner may throw an...

  • (1) (5 points) What does the following codes display? import java.util.; public class Test public static...

    (1) (5 points) What does the following codes display? import java.util.; public class Test public static void main(Stringl) args) PriorityQueuecinteger> queue - new PriorityQueuecintege>( Arrays.asList(60, 10, 50, 30, 40, 20)); while (lqueue.isEmpty)) System.out.print(queue.poll()+"") The program displays 60 10 50 30 40 20 b. The program displays 60 50 40 30 20 10 c. This problem displays 10 30 50 20 40 60 d. The program displays 10 20 30 40 50 60 e. There is no guarantee that the program...

  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

  • Import java.util.*; public class PairFinder { public static void main(String[] args) { Scanner sc...

    import java.util.*; public class PairFinder { public static void main(String[] args) { Scanner sc = new Scanner(System.in);    // Read in the value of k int k = Integer.parseInt(sc.nextLine());    // Read in the list of numbers int[] numbers; String input = sc.nextLine(); if (input.equals("")) { numbers = new int[0]; } else { String[] numberStrings = input.split(" "); numbers = new int[numberStrings.length]; for (int i = 0; i < numberStrings.length; i++) { numbers[i] = Integer.parseInt(numberStrings[i]); } }    System.out.println(findPairs(numbers, k)); }    //method that...

  • Code in java Using the template below: public class Lab03 { public static void main(String[] args)...

    Code in java Using the template below: public class Lab03 { public static void main(String[] args) { ArrayList<Integer> list1 = new ArrayList<Integer>(); Collections.addAll(list1, 1, 3, 5, 5 ); ArrayList<Integer> list2 = new ArrayList<Integer>(); Collections.addAll(list2, 3, 7, 3, 2, 4 ); ArrayList<Integer> result1= uniqueUnion(list1,list2); System.out.println(result1); Integer[] array = new Integer[]{ 29, 28, 27, 16, 15, -14, 3, -2, 2}; ArrayList<Integer> arrayList = new ArrayList<Integer>(Arrays.asList(array)); System.out.printf("The average is: %.2f%n", averagePositive(arrayList)); } // end main public static ArrayList<Integer> uniqueUnion(ArrayList<Integer> list1, ArrayList<Integer> list2) {...

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • What is output 1 in the code below? import java.util."; public class StackDemo { public static...

    What is output 1 in the code below? import java.util."; public class StackDemo { public static void main(String [] args) { Stack<Integer> intStack = new Stack<>(); Stack<Integer> tempStack = new Stack<>(); intStack.push(18); intStack.push(21); intStack.push(25); tempStack = intStack; while (!tempStack.empty() { System.out.print(tempStack.peek()+"");//output 1 tempStack.pop(); 3 System.out.println(); System.out.println(intStack.peek()); //output 2 25 18 21 • 25 21 18

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT