Strings
Arrays
Other
Operators
100

How would you check that two Strings str1 and str2 are the same string?

str1.equals(str2)

100

How would you create an array to store 5 integers?

int[] arr = new int[5];

100

How would you check that two doubles d1 and d2 are equal?

Math.abs(d1-d2) < 0.000001

100

What does the variable "result" contain?

int result = 6 + 6 * 2 / 3;

10

200

How would you get the first half of a String str (rounded down)?

str.substring(0, str.length()/2);

200

Write a method that finds the total product of all of the numbers in an array.

Answers will vary.

200

What is 47 in binary?

101111

200

What does the variable result contain after the following code is executed?

int result = 7;

result = result / 2;

result++;

result *= 2;

result--;

7
300

Write a method that counts the number of vowels in a String.

Answers will vary, but charAt or substring will be useful.

300

Write a method that finds the index of the last time that the number 5 shows up in an array.

Answers will vary, but it may be helpful to iterate from the back of the array.

300

Write a method that is given 3 doubles and finds the integer closest to sum of the 3 doubles.

Answers will vary.

300

What does the variable "result" contain?

int result = -5 % 3;

-2

400

Write a method that takes three Strings and returns the String that comes first alphabetically. This method should work regardless of the capitalization.

Answers will vary, but compareTo will be helpful.

400

Write a method that checks if every number in an array is at least 2 greater than the number that comes after it.

Answers will vary, but you will likely want to use "adjacent pairs" iteration

400

Which sorting algorithm is this?

public static void sort(int[] arr) {          
    for (int i = 0; i < arr.length; i++) {    
        int minIndex = i;                    
                                             
        for (int j = i; j < arr.length; j++) {
            if (arr[j] < arr[minIndex]) {    
                minIndex = j;                
            }                                
        }                                    
                                             
        int temp = arr[i];                    
        arr[i] = arr[minIndex];              
        arr[minIndex] = temp;                
    }                                        
}                                            

Selection sort

500

Write a method that counts the number of times the String "apple" shows up in another String.

Answers will vary, but indexOf() will be helpful.

500

Given two arrays, write a method that returns true if the arrays contain any of the same values, and returns false otherwise.

Answers will vary, but nested loops will likely be helpful.

500

Write a method that is given an int and counts how many of the digits in that number are even.

Answers will vary, but you likely want to use % 10 to get the digits and / 10 to iterate.

M
e
n
u