How would you check that two Strings str1 and str2 are the same string?
str1.equals(str2)
How would you create an array to store 5 integers?
int[] arr = new int[5];
How would you check that two doubles d1 and d2 are equal?
Math.abs(d1-d2) < 0.000001
What does the variable "result" contain?
int result = 6 + 6 * 2 / 3;
10
How would you get the first half of a String str (rounded down)?
str.substring(0, str.length()/2);
Write a method that finds the total product of all of the numbers in an array.
Answers will vary.
What is 47 in binary?
101111
What does the variable result contain after the following code is executed?
int result = 7;
result = result / 2;
result++;
result *= 2;
result--;
Write a method that counts the number of vowels in a String.
Answers will vary, but charAt or substring will be useful.
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.
Write a method that is given 3 doubles and finds the integer closest to sum of the 3 doubles.
Answers will vary.
What does the variable "result" contain?
int result = -5 % 3;
-2
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.
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
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
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.
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.
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.