Strings
ArrayList
Binary
2D Arrays
Searching and Sorting
100

What is a string?

An object of the String class that represents a sequence of characters.

100

Define an Array List that holds integer values and is called "boosh".

ArrayList<int> boosh = new ArrayList<int>();

100

what is 110 in decimal

6

100

How can you traverse a 2D array

using nested loops

100

On average, which of the following sort methods is the fastest:

Selection Sort

Merge Sort

Insertion Sort

Merge Sort

200

Can a string be changed after it has been created?

Once created, a string cannot be changed and none of its methods can change the string. This is because it immutable.

200
How do you add something to an Array List

.add() method

200
what is 30 in binary

11110

200

What is an ArrayIndexOutOfBoundsException

Error given when the code tries to access an invalid index for a given array

200

What order will this list be in after the 3rd pass of selection sort:

64, 25, 12, 22, 11

11, 12, 22, 25, 64  

300

What returns in the following code:

String s = new String ("classicaayush");

s.substring(2,8);

assica

300

What will be printed as a result of the code?

public static void main(String[] args)

{

   ArrayList<String> list = new ArrayList<String>();

    list.add("e");

    list.add(0, "yo");

    list.add("bob");

    list.add(2,"3");

    list.add("hi");

    list.add(1, "yan");

   System.out.println(list);

  }

[yo, yan, e, 3, bob, hi]

300

What is 11 in Hexadecimal

B

300

Fill in the missing code to print out [47, 51, 20]

public static void main(String[] args)

    {

        int[][] arr = { {47,3,12},{51,74,20} };

        *MISSING CODE*

    }

System.out.println(arr[0][0]);

System.out.println(arr[1][0]);

System.out.println(arr[1][2]);

300

What order will the list be in after the 5th pass of insertion sort:

12, 8, 41, 22, 34, 2, 56

8, 12, 22, 34, 41, 2, 56

400

The class Scroll is meant to take the first letter of a string and put it at the end. Fill in the missing code segment to make the class work as specified.

public class Scroll {

public static String scroll (String s1){ 

   
return (*MISSING CODE*);


}

s1.substring(1,s1.length()) + Character.toString(s1.charAt(0))

//could be other solutions

400

The smallest method is meant to find the smallest value in a list. Fill in the missing code segment so it works as specified:

public static int smallest(ArrayList<Integer> list)
{
    int smallest = list.get(0);
    for (int i = 1; i < 20; i++)
    {
       if(*MISSING CODE*)
       {
          smallest = list.get(i);
       }
   
    }
 }

(list.get(i) <= smallest)

400

what is 11101001 in decimal

233

400

What does this method do:

public static double something(int[][] nums){

        int x = 0;

        int y = 0;

        for (int i = 0; i < nums.length; i++)

            for (int j = 0; j < nums[i].length; j++) {

                x += nums[i][j];

                y ++;

            }    

        return (double)x/y;            

    }

finds the average of the numbers in the array.

400

Use merge sort to fully sort this list and show the steps:

42, 12, 34, 43, 9, 32, 2

42, 12, 34, 43, 9, 32, 2

42, 12, 34, 43    9, 32, 2,

42, 12    34, 43    9, 32    2,

42   12    34    43    9    32    2

12, 42    34, 43    9, 32    2,

12, 34, 42, 43    2, 9, 32,

2, 9, 12, 32, 34, 42,43


500

What is returned in the following code segment

public static void main(String[] args)
   {
         StringBuffer s = new StringBuffer("Aayan>");
             string(s);
         System.out.println(s);
   }
 
  public static void string(StringBuffer s){
   s.append("Deven");

  }

Aayan>Deven

500

What does this method do:

public static void something(ArrayList<String> list) {
   
          for(int i = 0; i < list.size() / 2; i++) {
          String temp = list.get(i); 

          list.set(i, list.get(list.size()-1-i));
          list.set(list.size()-1-i, temp);
          }
          System.out.println(list);
    }

This method reverses the content in the list

500

What is 17AC82 in Hexidecimal to Octal

5726202

500

The largest method is meant to find the largest value in a 2D array. Write a nested for each loop for this method so that the method works as intended.


public static int largest(int[][] nums){

        int large = nums[0][0];

        *MISSING CODE*

        return large;            

    }

for (int[] row: nums)

            for (int col: row)

                if (col > large)

                    large = col;

500

Use quick sort to fully sort this list and show the steps:

13, 4, 23, 3, 45, 50, 5

13, 4, 23, 3, 45, 50, 5

3, 4, 23, 5, 45, 50, 13

3, 4, 5, 13, 45, 50, 23

3, 4, 5, 13, 23, 45, 50

3, 4, 5, 13, 23, 45, 50