instruction stringclasses 7
values | input stringclasses 1
value | output stringlengths 204 833 | language stringclasses 1
value | category stringclasses 4
values | difficulty stringclasses 2
values |
|---|---|---|---|---|---|
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> value, List<Integer> str) {
if (value == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integ... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> arr, List<Integer> list) {
if (arr == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> s, List<Integer> text) {
if (s == null || text == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> n ... | java | function | medium | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int max_alt(int[] arr) {
if (arr == null || arr.length == 0) {
throw new IllegalArgumentException("arr must not be null or empty");
}
int max = arr[0];
for (int v : arr) {
if (v > max) {
max = v;
... | java | completion | easy | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafeEx(String s) {
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + s);
return 0;
}
}
} | java | exception-handling | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_new(int value, int s) {
if (s == 0) {
throw new IllegalArgumentException("s must not be zero");
}
return (double) value / s;
}
} | java | bug-fix | easy | |
Write a Java method that checks whether a number is prime. | public class MathUtils {
public static boolean isPrime_alt(int str) {
if (str < 2) {
return false;
}
for (int i = 2; i * i <= str; i++) {
if (str % i == 0) {
return false;
}
}
return true;
}
} | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted(List<Integer> str, List<Integer> n) {
if (str == null || n == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = ... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_new(int arr, int input) {
if (input == 0) {
throw new IllegalArgumentException("input must not be zero");
}
return (double) arr / input;
}
} | java | bug-fix | easy | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int max_v2(int[] s) {
if (s == null || s.length == 0) {
throw new IllegalArgumentException("s must not be null or empty");
}
int max = s[0];
for (int v : s) {
if (v > max) {
max = v;
}
... | java | completion | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> input, List<Integer> s) {
if (input == null || s == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> ... | java | function | medium | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowels(String n) {
if (n == null) {
return 0;
}
int count = 0;
for (char c : n.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return coun... | java | function | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedHelper(List<Integer> nums, List<Integer> list) {
if (nums == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Int... | java | function | medium | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseString_v2(String str) {
if (str == null) {
return null;
}
return new StringBuilder(str).reverse().toString();
}
} | java | function | easy | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseString_new(String text) {
if (text == null) {
return null;
}
return new StringBuilder(text).reverse().toString();
}
} | java | function | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideHelper(int arr, int n) {
if (n == 0) {
throw new IllegalArgumentException("n must not be zero");
}
return (double) arr / n;
}
} | java | bug-fix | easy | |
Write a Java method that checks whether a number is prime. | public class MathUtils {
public static boolean isPrimeHelper(int input) {
if (input < 2) {
return false;
}
for (int i = 2; i * i <= input; i++) {
if (input % i == 0) {
return false;
}
}
return true;
}
} | java | function | medium | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseString_new(String s) {
if (s == null) {
return null;
}
return new StringBuilder(s).reverse().toString();
}
} | java | function | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedEx(List<Integer> nums, List<Integer> nums) {
if (nums == null || nums == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer... | java | function | medium | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafeEx(String arr) {
try {
return Integer.parseInt(arr);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + arr);
return 0;
}
}
} | java | exception-handling | medium | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseStringHelper(String s) {
if (s == null) {
return null;
}
return new StringBuilder(s).reverse().toString();
}
} | java | function | easy | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowelsEx(String text) {
if (text == null) {
return 0;
}
int count = 0;
for (char c : text.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
... | java | function | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideEx(int value, int str) {
if (str == 0) {
throw new IllegalArgumentException("str must not be zero");
}
return (double) value / str;
}
} | java | bug-fix | easy | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int max(int[] str) {
if (str == null || str.length == 0) {
throw new IllegalArgumentException("str must not be null or empty");
}
int max = str[0];
for (int v : str) {
if (v > max) {
max = v;
... | java | completion | easy | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int max_alt(int[] nums) {
if (nums == null || nums.length == 0) {
throw new IllegalArgumentException("nums must not be null or empty");
}
int max = nums[0];
for (int v : nums) {
if (v > max) {
max = v;
... | java | completion | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedEx(List<Integer> arr, List<Integer> value) {
if (arr == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> n, List<Integer> input) {
if (n == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> ... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_alt(int value, int s) {
if (s == 0) {
throw new IllegalArgumentException("s must not be zero");
}
return (double) value / s;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedEx(List<Integer> list, List<Integer> input) {
if (list == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integ... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> arr, List<Integer> text) {
if (arr == null || text == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideEx(int input, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) input / text;
}
} | java | bug-fix | easy | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseString_v2(String list) {
if (list == null) {
return null;
}
return new StringBuilder(list).reverse().toString();
}
} | java | function | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideHelper(int str, int s) {
if (s == 0) {
throw new IllegalArgumentException("s must not be zero");
}
return (double) str / s;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> s, List<Integer> input) {
if (s == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> ... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideHelper(int arr, int s) {
if (s == 0) {
throw new IllegalArgumentException("s must not be zero");
}
return (double) arr / s;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedHelper(List<Integer> n, List<Integer> list) {
if (n == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> ... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_alt(int s, int arr) {
if (arr == 0) {
throw new IllegalArgumentException("arr must not be zero");
}
return (double) s / arr;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> value, List<Integer> list) {
if (value == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Inte... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_new(List<Integer> nums, List<Integer> value) {
if (nums == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Int... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted(List<Integer> input, List<Integer> input) {
if (input == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integ... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> s, List<Integer> list) {
if (s == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> arr... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted(List<Integer> value, List<Integer> str) {
if (value == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> ... | java | function | medium | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int maxEx(int[] value) {
if (value == null || value.length == 0) {
throw new IllegalArgumentException("value must not be null or empty");
}
int max = value[0];
for (int v : value) {
if (v > max) {
max = ... | java | completion | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_alt(int text, int list) {
if (list == 0) {
throw new IllegalArgumentException("list must not be zero");
}
return (double) text / list;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_new(List<Integer> s, List<Integer> list) {
if (s == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> n ... | java | function | medium | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseStringHelper(String arr) {
if (arr == null) {
return null;
}
return new StringBuilder(arr).reverse().toString();
}
} | java | function | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_v2(int input, int list) {
if (list == 0) {
throw new IllegalArgumentException("list must not be zero");
}
return (double) input / list;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> text, List<Integer> value) {
if (text == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Int... | java | function | medium | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafeEx(String list) {
try {
return Integer.parseInt(list);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + list);
return 0;
}
}
} | java | exception-handling | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_alt(int arr, int n) {
if (n == 0) {
throw new IllegalArgumentException("n must not be zero");
}
return (double) arr / n;
}
} | java | bug-fix | easy | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowels_v2(String s) {
if (s == null) {
return 0;
}
int count = 0;
for (char c : s.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return c... | java | function | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_alt(List<Integer> text, List<Integer> n) {
if (text == null || n == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> s ... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted(List<Integer> s, List<Integer> str) {
if (s == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> n = new ... | java | function | medium | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafe(String input) {
try {
return Integer.parseInt(input);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + input);
return 0;
}
}
} | java | exception-handling | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_new(List<Integer> value, List<Integer> text) {
if (value == null || text == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Int... | java | function | medium | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowelsHelper(String str) {
if (str == null) {
return 0;
}
int count = 0;
for (char c : str.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
... | java | function | easy | |
Write a Java method that checks whether a number is prime. | public class MathUtils {
public static boolean isPrimeEx(int n) {
if (n < 2) {
return false;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
} | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> str, List<Integer> list) {
if (str == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer>... | java | function | medium | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int maxHelper(int[] input) {
if (input == null || input.length == 0) {
throw new IllegalArgumentException("input must not be null or empty");
}
int max = input[0];
for (int v : input) {
if (v > max) {
ma... | java | completion | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_new(int n, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) n / text;
}
} | java | bug-fix | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideEx(int text, int s) {
if (s == 0) {
throw new IllegalArgumentException("s must not be zero");
}
return (double) text / s;
}
} | java | bug-fix | easy | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int max_new(int[] arr) {
if (arr == null || arr.length == 0) {
throw new IllegalArgumentException("arr must not be null or empty");
}
int max = arr[0];
for (int v : arr) {
if (v > max) {
max = v;
... | java | completion | easy | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int maxHelper(int[] list) {
if (list == null || list.length == 0) {
throw new IllegalArgumentException("list must not be null or empty");
}
int max = list[0];
for (int v : list) {
if (v > max) {
max = v;... | java | completion | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted(List<Integer> s, List<Integer> input) {
if (s == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str ... | java | function | medium | |
Write a Java method that checks whether a number is prime. | public class MathUtils {
public static boolean isPrimeHelper(int s) {
if (s < 2) {
return false;
}
for (int i = 2; i * i <= s; i++) {
if (s % i == 0) {
return false;
}
}
return true;
}
} | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_v2(int nums, int arr) {
if (arr == 0) {
throw new IllegalArgumentException("arr must not be zero");
}
return (double) nums / arr;
}
} | java | bug-fix | easy | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafeHelper(String s) {
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + s);
return 0;
}
}
} | java | exception-handling | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide(int nums, int value) {
if (value == 0) {
throw new IllegalArgumentException("value must not be zero");
}
return (double) nums / value;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> input, List<Integer> value) {
if (input == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<In... | java | function | medium | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseString_v2(String s) {
if (s == null) {
return null;
}
return new StringBuilder(s).reverse().toString();
}
} | java | function | easy | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafe_alt(String text) {
try {
return Integer.parseInt(text);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + text);
return 0;
}
}
} | java | exception-handling | medium | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafe_v2(String text) {
try {
return Integer.parseInt(text);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + text);
return 0;
}
}
} | java | exception-handling | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> arr, List<Integer> nums) {
if (arr == null || nums == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer>... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideEx(int value, int list) {
if (list == 0) {
throw new IllegalArgumentException("list must not be zero");
}
return (double) value / list;
}
} | java | bug-fix | easy | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseStringHelper(String nums) {
if (nums == null) {
return null;
}
return new StringBuilder(nums).reverse().toString();
}
} | java | function | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> str, List<Integer> value) {
if (str == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Intege... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_v2(int nums, int s) {
if (s == 0) {
throw new IllegalArgumentException("s must not be zero");
}
return (double) nums / s;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedHelper(List<Integer> text, List<Integer> text) {
if (text == null || text == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Int... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_alt(int value, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) value / text;
}
} | java | bug-fix | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> s, List<Integer> text) {
if (s == null || text == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> inp... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedHelper(List<Integer> list, List<Integer> input) {
if (list == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<I... | java | function | medium | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted_v2(List<Integer> value, List<Integer> list) {
if (value == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Inte... | java | function | medium | |
Write a Java method that parses an integer from a string safely using try-catch. | public class Utils {
public static int parseIntSafe_v2(String list) {
try {
return Integer.parseInt(list);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + list);
return 0;
}
}
} | java | exception-handling | medium | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int maxEx(int[] n) {
if (n == null || n.length == 0) {
throw new IllegalArgumentException("n must not be null or empty");
}
int max = n[0];
for (int v : n) {
if (v > max) {
max = v;
}
... | java | completion | easy | |
Write a Java method that reverses a string. | public class StringUtils {
public static String reverseString(String value) {
if (value == null) {
return null;
}
return new StringBuilder(value).reverse().toString();
}
} | java | function | easy | |
Complete the following Java method so it returns the maximum value in an array. | public class ArrayUtils {
public static int max_alt(int[] s) {
if (s == null || s.length == 0) {
throw new IllegalArgumentException("s must not be null or empty");
}
int max = s[0];
for (int v : s) {
if (v > max) {
max = v;
}
... | java | completion | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSortedHelper(List<Integer> text, List<Integer> arr) {
if (text == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integ... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_alt(int value, int arr) {
if (arr == 0) {
throw new IllegalArgumentException("arr must not be zero");
}
return (double) value / arr;
}
} | java | bug-fix | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_alt(int str, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) str / text;
}
} | java | bug-fix | easy | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide(int value, int list) {
if (list == 0) {
throw new IllegalArgumentException("list must not be zero");
}
return (double) value / list;
}
} | java | bug-fix | easy | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowels_new(String arr) {
if (arr == null) {
return 0;
}
int count = 0;
for (char c : arr.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
r... | java | function | easy | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowelsHelper(String text) {
if (text == null) {
return 0;
}
int count = 0;
for (char c : text.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
... | java | function | easy | |
Write a Java method that merges two sorted lists of integers into a new sorted list. | import java.util.ArrayList;
import java.util.List;
public class CollectionUtils {
public static List<Integer> mergeSorted(List<Integer> s, List<Integer> arr) {
if (s == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> text = n... | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divide_v2(int s, int n) {
if (n == 0) {
throw new IllegalArgumentException("n must not be zero");
}
return (double) s / n;
}
} | java | bug-fix | easy | |
Write a Java method that checks whether a number is prime. | public class MathUtils {
public static boolean isPrimeEx(int list) {
if (list < 2) {
return false;
}
for (int i = 2; i * i <= list; i++) {
if (list % i == 0) {
return false;
}
}
return true;
}
} | java | function | medium | |
Fix the following Java method so it avoids division by zero. | public class MathUtils {
public static double divideHelper(int nums, int list) {
if (list == 0) {
throw new IllegalArgumentException("list must not be zero");
}
return (double) nums / list;
}
} | java | bug-fix | easy | |
Write a Java method that checks whether a number is prime. | public class MathUtils {
public static boolean isPrimeHelper(int value) {
if (value < 2) {
return false;
}
for (int i = 2; i * i <= value; i++) {
if (value % i == 0) {
return false;
}
}
return true;
}
} | java | function | medium | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowels(String input) {
if (input == null) {
return 0;
}
int count = 0;
for (char c : input.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
... | java | function | easy | |
Write a Java method that counts the number of vowels in a string. | public class StringUtils {
public static int countVowelsEx(String list) {
if (list == null) {
return 0;
}
int count = 0;
for (char c : list.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
... | java | function | easy | |
Write a Java method that checks whether a number is prime. | public class MathUtils {
public static boolean isPrimeHelper(int nums) {
if (nums < 2) {
return false;
}
for (int i = 2; i * i <= nums; i++) {
if (nums % i == 0) {
return false;
}
}
return true;
}
} | java | function | medium |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.