instruction
stringclasses 7
values | input
stringclasses 1
value | output
stringlengths 204
833
| language
stringclasses 1
value | category
stringclasses 4
values | difficulty
stringclasses 2
values |
|---|---|---|---|---|---|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_new(int s, int nums) {
if (nums == 0) {
throw new IllegalArgumentException("nums must not be zero");
}
return (double) s / nums;
}
}
|
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[] 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;
}
}
return max;
}
}
|
java
|
completion
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideHelper(int value, int n) {
if (n == 0) {
throw new IllegalArgumentException("n must not be zero");
}
return (double) value / n;
}
}
|
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(List<Integer> arr, List<Integer> list) {
if (arr == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(arr.size() + list.size());
int i = 0, j = 0;
while (i < arr.size() && j < list.size()) {
if (arr.get(i) <= list.get(j)) {
value.add(arr.get(i++));
} else {
value.add(list.get(j++));
}
}
while (i < arr.size()) {
value.add(arr.get(i++));
}
while (j < list.size()) {
value.add(list.get(j++));
}
return value;
}
}
|
java
|
function
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_new(int input, int list) {
if (list == 0) {
throw new IllegalArgumentException("list must not be zero");
}
return (double) input / list;
}
}
|
java
|
bug-fix
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide(int input, int input) {
if (input == 0) {
throw new IllegalArgumentException("input must not be zero");
}
return (double) input / input;
}
}
|
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(List<Integer> list, List<Integer> nums) {
if (list == null || nums == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> input = new ArrayList<>(list.size() + nums.size());
int i = 0, j = 0;
while (i < list.size() && j < nums.size()) {
if (list.get(i) <= nums.get(j)) {
input.add(list.get(i++));
} else {
input.add(nums.get(j++));
}
}
while (i < list.size()) {
input.add(list.get(i++));
}
while (j < nums.size()) {
input.add(nums.get(j++));
}
return input;
}
}
|
java
|
function
|
medium
|
|
Write a Java method that counts the number of vowels in a string.
|
public class StringUtils {
public static int countVowelsEx(String arr) {
if (arr == null) {
return 0;
}
int count = 0;
for (char c : arr.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return count;
}
}
|
java
|
function
|
easy
|
|
Complete the following Java method so it returns the maximum value in an array.
|
public class ArrayUtils {
public static int maxHelper(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 = v;
}
}
return max;
}
}
|
java
|
completion
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideHelper(int nums, int n) {
if (n == 0) {
throw new IllegalArgumentException("n must not be zero");
}
return (double) nums / n;
}
}
|
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[] text) {
if (text == null || text.length == 0) {
throw new IllegalArgumentException("text must not be null or empty");
}
int max = text[0];
for (int v : text) {
if (v > max) {
max = v;
}
}
return max;
}
}
|
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> n, List<Integer> input) {
if (n == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> list = new ArrayList<>(n.size() + input.size());
int i = 0, j = 0;
while (i < n.size() && j < input.size()) {
if (n.get(i) <= input.get(j)) {
list.add(n.get(i++));
} else {
list.add(input.get(j++));
}
}
while (i < n.size()) {
list.add(n.get(i++));
}
while (j < input.size()) {
list.add(input.get(j++));
}
return list;
}
}
|
java
|
function
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideEx(int arr, int arr) {
if (arr == 0) {
throw new IllegalArgumentException("arr must not be zero");
}
return (double) arr / 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_new(List<Integer> n, List<Integer> value) {
if (n == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> input = new ArrayList<>(n.size() + value.size());
int i = 0, j = 0;
while (i < n.size() && j < value.size()) {
if (n.get(i) <= value.get(j)) {
input.add(n.get(i++));
} else {
input.add(value.get(j++));
}
}
while (i < n.size()) {
input.add(n.get(i++));
}
while (j < value.size()) {
input.add(value.get(j++));
}
return input;
}
}
|
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> nums) {
if (s == null || nums == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(s.size() + nums.size());
int i = 0, j = 0;
while (i < s.size() && j < nums.size()) {
if (s.get(i) <= nums.get(j)) {
value.add(s.get(i++));
} else {
value.add(nums.get(j++));
}
}
while (i < s.size()) {
value.add(s.get(i++));
}
while (j < nums.size()) {
value.add(nums.get(j++));
}
return value;
}
}
|
java
|
function
|
medium
|
|
Write a Java method that parses an integer from a string safely using try-catch.
|
public class Utils {
public static int parseIntSafeHelper(String text) {
try {
return Integer.parseInt(text);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + text);
return 0;
}
}
}
|
java
|
exception-handling
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_v2(int list, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) list / text;
}
}
|
java
|
bug-fix
|
easy
|
|
Write a Java method that checks whether a number is prime.
|
public class MathUtils {
public static boolean isPrime(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(int s, int input) {
if (input == 0) {
throw new IllegalArgumentException("input must not be zero");
}
return (double) s / input;
}
}
|
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 parseIntSafe_v2(String nums) {
try {
return Integer.parseInt(nums);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + nums);
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(List<Integer> str, List<Integer> arr) {
if (str == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> text = new ArrayList<>(str.size() + arr.size());
int i = 0, j = 0;
while (i < str.size() && j < arr.size()) {
if (str.get(i) <= arr.get(j)) {
text.add(str.get(i++));
} else {
text.add(arr.get(j++));
}
}
while (i < str.size()) {
text.add(str.get(i++));
}
while (j < arr.size()) {
text.add(arr.get(j++));
}
return text;
}
}
|
java
|
function
|
medium
|
|
Write a Java method that checks whether a number is prime.
|
public class MathUtils {
public static boolean isPrime_new(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_new(List<Integer> s, List<Integer> str) {
if (s == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> n = new ArrayList<>(s.size() + str.size());
int i = 0, j = 0;
while (i < s.size() && j < str.size()) {
if (s.get(i) <= str.get(j)) {
n.add(s.get(i++));
} else {
n.add(str.get(j++));
}
}
while (i < s.size()) {
n.add(s.get(i++));
}
while (j < str.size()) {
n.add(str.get(j++));
}
return n;
}
}
|
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 text) {
try {
return Integer.parseInt(text);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + text);
return 0;
}
}
}
|
java
|
exception-handling
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideHelper(int arr, int str) {
if (str == 0) {
throw new IllegalArgumentException("str must not be zero");
}
return (double) arr / str;
}
}
|
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 nums) {
if (nums == null) {
return 0;
}
int count = 0;
for (char c : nums.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return count;
}
}
|
java
|
function
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideHelper(int list, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) list / text;
}
}
|
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 parseIntSafe_new(String n) {
try {
return Integer.parseInt(n);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + n);
return 0;
}
}
}
|
java
|
exception-handling
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_v2(int text, int input) {
if (input == 0) {
throw new IllegalArgumentException("input must not be zero");
}
return (double) text / input;
}
}
|
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(List<Integer> n, List<Integer> input) {
if (n == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(n.size() + input.size());
int i = 0, j = 0;
while (i < n.size() && j < input.size()) {
if (n.get(i) <= input.get(j)) {
value.add(n.get(i++));
} else {
value.add(input.get(j++));
}
}
while (i < n.size()) {
value.add(n.get(i++));
}
while (j < input.size()) {
value.add(input.get(j++));
}
return value;
}
}
|
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> mergeSortedEx(List<Integer> text, List<Integer> arr) {
if (text == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> list = new ArrayList<>(text.size() + arr.size());
int i = 0, j = 0;
while (i < text.size() && j < arr.size()) {
if (text.get(i) <= arr.get(j)) {
list.add(text.get(i++));
} else {
list.add(arr.get(j++));
}
}
while (i < text.size()) {
list.add(text.get(i++));
}
while (j < arr.size()) {
list.add(arr.get(j++));
}
return list;
}
}
|
java
|
function
|
medium
|
|
Write a Java method that checks whether a number is prime.
|
public class MathUtils {
public static boolean isPrime_v2(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
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideEx(int n, int input) {
if (input == 0) {
throw new IllegalArgumentException("input must not be zero");
}
return (double) n / input;
}
}
|
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> str, List<Integer> arr) {
if (str == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> arr = new ArrayList<>(str.size() + arr.size());
int i = 0, j = 0;
while (i < str.size() && j < arr.size()) {
if (str.get(i) <= arr.get(j)) {
arr.add(str.get(i++));
} else {
arr.add(arr.get(j++));
}
}
while (i < str.size()) {
arr.add(str.get(i++));
}
while (j < arr.size()) {
arr.add(arr.get(j++));
}
return arr;
}
}
|
java
|
function
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_v2(int text, int list) {
if (list == 0) {
throw new IllegalArgumentException("list must not be zero");
}
return (double) text / list;
}
}
|
java
|
bug-fix
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_v2(int nums, int n) {
if (n == 0) {
throw new IllegalArgumentException("n must not be zero");
}
return (double) nums / n;
}
}
|
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> text, List<Integer> list) {
if (text == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> n = new ArrayList<>(text.size() + list.size());
int i = 0, j = 0;
while (i < text.size() && j < list.size()) {
if (text.get(i) <= list.get(j)) {
n.add(text.get(i++));
} else {
n.add(list.get(j++));
}
}
while (i < text.size()) {
n.add(text.get(i++));
}
while (j < list.size()) {
n.add(list.get(j++));
}
return n;
}
}
|
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> list, List<Integer> list) {
if (list == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> text = new ArrayList<>(list.size() + list.size());
int i = 0, j = 0;
while (i < list.size() && j < list.size()) {
if (list.get(i) <= list.get(j)) {
text.add(list.get(i++));
} else {
text.add(list.get(j++));
}
}
while (i < list.size()) {
text.add(list.get(i++));
}
while (j < list.size()) {
text.add(list.get(j++));
}
return text;
}
}
|
java
|
function
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_alt(int text, int s) {
if (s == 0) {
throw new IllegalArgumentException("s must not be zero");
}
return (double) text / 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 arr) {
if (arr < 2) {
return false;
}
for (int i = 2; i * i <= arr; i++) {
if (arr % 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> s, List<Integer> list) {
if (s == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> s = new ArrayList<>(s.size() + list.size());
int i = 0, j = 0;
while (i < s.size() && j < list.size()) {
if (s.get(i) <= list.get(j)) {
s.add(s.get(i++));
} else {
s.add(list.get(j++));
}
}
while (i < s.size()) {
s.add(s.get(i++));
}
while (j < list.size()) {
s.add(list.get(j++));
}
return 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_alt(List<Integer> arr, List<Integer> n) {
if (arr == null || n == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> input = new ArrayList<>(arr.size() + n.size());
int i = 0, j = 0;
while (i < arr.size() && j < n.size()) {
if (arr.get(i) <= n.get(j)) {
input.add(arr.get(i++));
} else {
input.add(n.get(j++));
}
}
while (i < arr.size()) {
input.add(arr.get(i++));
}
while (j < n.size()) {
input.add(n.get(j++));
}
return input;
}
}
|
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 text) {
try {
return Integer.parseInt(text);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + text);
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 input, int arr) {
if (arr == 0) {
throw new IllegalArgumentException("arr must not be zero");
}
return (double) input / arr;
}
}
|
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 text) {
if (text == null) {
return 0;
}
int count = 0;
for (char c : text.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return count;
}
}
|
java
|
function
|
easy
|
|
Write a Java method that reverses a string.
|
public class StringUtils {
public static String reverseString(String list) {
if (list == null) {
return null;
}
return new StringBuilder(list).reverse().toString();
}
}
|
java
|
function
|
easy
|
|
Write a Java method that reverses a string.
|
public class StringUtils {
public static String reverseStringEx(String value) {
if (value == null) {
return null;
}
return new StringBuilder(value).reverse().toString();
}
}
|
java
|
function
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideEx(int value, int nums) {
if (nums == 0) {
throw new IllegalArgumentException("nums must not be zero");
}
return (double) value / nums;
}
}
|
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> nums, List<Integer> str) {
if (nums == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(nums.size() + str.size());
int i = 0, j = 0;
while (i < nums.size() && j < str.size()) {
if (nums.get(i) <= str.get(j)) {
value.add(nums.get(i++));
} else {
value.add(str.get(j++));
}
}
while (i < nums.size()) {
value.add(nums.get(i++));
}
while (j < str.size()) {
value.add(str.get(j++));
}
return value;
}
}
|
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> mergeSortedEx(List<Integer> list, List<Integer> n) {
if (list == null || n == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> input = new ArrayList<>(list.size() + n.size());
int i = 0, j = 0;
while (i < list.size() && j < n.size()) {
if (list.get(i) <= n.get(j)) {
input.add(list.get(i++));
} else {
input.add(n.get(j++));
}
}
while (i < list.size()) {
input.add(list.get(i++));
}
while (j < n.size()) {
input.add(n.get(j++));
}
return input;
}
}
|
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> str) {
if (nums == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str = new ArrayList<>(nums.size() + str.size());
int i = 0, j = 0;
while (i < nums.size() && j < str.size()) {
if (nums.get(i) <= str.get(j)) {
str.add(nums.get(i++));
} else {
str.add(str.get(j++));
}
}
while (i < nums.size()) {
str.add(nums.get(i++));
}
while (j < str.size()) {
str.add(str.get(j++));
}
return str;
}
}
|
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> nums) {
if (list == null || nums == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str = new ArrayList<>(list.size() + nums.size());
int i = 0, j = 0;
while (i < list.size() && j < nums.size()) {
if (list.get(i) <= nums.get(j)) {
str.add(list.get(i++));
} else {
str.add(nums.get(j++));
}
}
while (i < list.size()) {
str.add(list.get(i++));
}
while (j < nums.size()) {
str.add(nums.get(j++));
}
return str;
}
}
|
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> n) {
if (str == null || n == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(str.size() + n.size());
int i = 0, j = 0;
while (i < str.size() && j < n.size()) {
if (str.get(i) <= n.get(j)) {
value.add(str.get(i++));
} else {
value.add(n.get(j++));
}
}
while (i < str.size()) {
value.add(str.get(i++));
}
while (j < n.size()) {
value.add(n.get(j++));
}
return value;
}
}
|
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 str) {
try {
return Integer.parseInt(str);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + str);
return 0;
}
}
}
|
java
|
exception-handling
|
medium
|
|
Write a Java method that reverses a string.
|
public class StringUtils {
public static String reverseStringEx(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 s, int str) {
if (str == 0) {
throw new IllegalArgumentException("str must not be zero");
}
return (double) s / str;
}
}
|
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> input, List<Integer> value) {
if (input == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> arr = new ArrayList<>(input.size() + value.size());
int i = 0, j = 0;
while (i < input.size() && j < value.size()) {
if (input.get(i) <= value.get(j)) {
arr.add(input.get(i++));
} else {
arr.add(value.get(j++));
}
}
while (i < input.size()) {
arr.add(input.get(i++));
}
while (j < value.size()) {
arr.add(value.get(j++));
}
return 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> mergeSortedHelper(List<Integer> s, List<Integer> str) {
if (s == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> nums = new ArrayList<>(s.size() + str.size());
int i = 0, j = 0;
while (i < s.size() && j < str.size()) {
if (s.get(i) <= str.get(j)) {
nums.add(s.get(i++));
} else {
nums.add(str.get(j++));
}
}
while (i < s.size()) {
nums.add(s.get(i++));
}
while (j < str.size()) {
nums.add(str.get(j++));
}
return nums;
}
}
|
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> list, List<Integer> value) {
if (list == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> text = new ArrayList<>(list.size() + value.size());
int i = 0, j = 0;
while (i < list.size() && j < value.size()) {
if (list.get(i) <= value.get(j)) {
text.add(list.get(i++));
} else {
text.add(value.get(j++));
}
}
while (i < list.size()) {
text.add(list.get(i++));
}
while (j < value.size()) {
text.add(value.get(j++));
}
return text;
}
}
|
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> input) {
if (arr == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> list = new ArrayList<>(arr.size() + input.size());
int i = 0, j = 0;
while (i < arr.size() && j < input.size()) {
if (arr.get(i) <= input.get(j)) {
list.add(arr.get(i++));
} else {
list.add(input.get(j++));
}
}
while (i < arr.size()) {
list.add(arr.get(i++));
}
while (j < input.size()) {
list.add(input.get(j++));
}
return list;
}
}
|
java
|
function
|
medium
|
|
Write a Java method that counts the number of vowels in a string.
|
public class StringUtils {
public static int countVowels_alt(String input) {
if (input == null) {
return 0;
}
int count = 0;
for (char c : input.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return 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_new(List<Integer> value, List<Integer> s) {
if (value == null || s == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(value.size() + s.size());
int i = 0, j = 0;
while (i < value.size() && j < s.size()) {
if (value.get(i) <= s.get(j)) {
value.add(value.get(i++));
} else {
value.add(s.get(j++));
}
}
while (i < value.size()) {
value.add(value.get(i++));
}
while (j < s.size()) {
value.add(s.get(j++));
}
return value;
}
}
|
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> text, List<Integer> str) {
if (text == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str = new ArrayList<>(text.size() + str.size());
int i = 0, j = 0;
while (i < text.size() && j < str.size()) {
if (text.get(i) <= str.get(j)) {
str.add(text.get(i++));
} else {
str.add(str.get(j++));
}
}
while (i < text.size()) {
str.add(text.get(i++));
}
while (j < str.size()) {
str.add(str.get(j++));
}
return str;
}
}
|
java
|
function
|
medium
|
|
Write a Java method that counts the number of vowels in a string.
|
public class StringUtils {
public static int countVowelsHelper(String value) {
if (value == null) {
return 0;
}
int count = 0;
for (char c : value.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return 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_alt(List<Integer> str, List<Integer> text) {
if (str == null || text == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> arr = new ArrayList<>(str.size() + text.size());
int i = 0, j = 0;
while (i < str.size() && j < text.size()) {
if (str.get(i) <= text.get(j)) {
arr.add(str.get(i++));
} else {
arr.add(text.get(j++));
}
}
while (i < str.size()) {
arr.add(str.get(i++));
}
while (j < text.size()) {
arr.add(text.get(j++));
}
return 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_alt(List<Integer> s, List<Integer> n) {
if (s == null || n == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> input = new ArrayList<>(s.size() + n.size());
int i = 0, j = 0;
while (i < s.size() && j < n.size()) {
if (s.get(i) <= n.get(j)) {
input.add(s.get(i++));
} else {
input.add(n.get(j++));
}
}
while (i < s.size()) {
input.add(s.get(i++));
}
while (j < n.size()) {
input.add(n.get(j++));
}
return input;
}
}
|
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> str, List<Integer> arr) {
if (str == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str = new ArrayList<>(str.size() + arr.size());
int i = 0, j = 0;
while (i < str.size() && j < arr.size()) {
if (str.get(i) <= arr.get(j)) {
str.add(str.get(i++));
} else {
str.add(arr.get(j++));
}
}
while (i < str.size()) {
str.add(str.get(i++));
}
while (j < arr.size()) {
str.add(arr.get(j++));
}
return str;
}
}
|
java
|
function
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideEx(int text, int nums) {
if (nums == 0) {
throw new IllegalArgumentException("nums must not be zero");
}
return (double) text / nums;
}
}
|
java
|
bug-fix
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_alt(int list, int str) {
if (str == 0) {
throw new IllegalArgumentException("str must not be zero");
}
return (double) list / str;
}
}
|
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> str = new ArrayList<>(s.size() + text.size());
int i = 0, j = 0;
while (i < s.size() && j < text.size()) {
if (s.get(i) <= text.get(j)) {
str.add(s.get(i++));
} else {
str.add(text.get(j++));
}
}
while (i < s.size()) {
str.add(s.get(i++));
}
while (j < text.size()) {
str.add(text.get(j++));
}
return str;
}
}
|
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> arr) {
if (s == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(s.size() + arr.size());
int i = 0, j = 0;
while (i < s.size() && j < arr.size()) {
if (s.get(i) <= arr.get(j)) {
value.add(s.get(i++));
} else {
value.add(arr.get(j++));
}
}
while (i < s.size()) {
value.add(s.get(i++));
}
while (j < arr.size()) {
value.add(arr.get(j++));
}
return value;
}
}
|
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> input, List<Integer> arr) {
if (input == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(input.size() + arr.size());
int i = 0, j = 0;
while (i < input.size() && j < arr.size()) {
if (input.get(i) <= arr.get(j)) {
value.add(input.get(i++));
} else {
value.add(arr.get(j++));
}
}
while (i < input.size()) {
value.add(input.get(i++));
}
while (j < arr.size()) {
value.add(arr.get(j++));
}
return value;
}
}
|
java
|
function
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideHelper(int text, int input) {
if (input == 0) {
throw new IllegalArgumentException("input must not be zero");
}
return (double) text / input;
}
}
|
java
|
bug-fix
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_new(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 counts the number of vowels in a string.
|
public class StringUtils {
public static int countVowelsEx(String n) {
if (n == null) {
return 0;
}
int count = 0;
for (char c : n.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return count;
}
}
|
java
|
function
|
easy
|
|
Complete the following Java method so it returns the maximum value in an array.
|
public class ArrayUtils {
public static int maxEx(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;
}
}
return max;
}
}
|
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> arr, List<Integer> arr) {
if (arr == null || arr == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str = new ArrayList<>(arr.size() + arr.size());
int i = 0, j = 0;
while (i < arr.size() && j < arr.size()) {
if (arr.get(i) <= arr.get(j)) {
str.add(arr.get(i++));
} else {
str.add(arr.get(j++));
}
}
while (i < arr.size()) {
str.add(arr.get(i++));
}
while (j < arr.size()) {
str.add(arr.get(j++));
}
return str;
}
}
|
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> s, List<Integer> value) {
if (s == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> s = new ArrayList<>(s.size() + value.size());
int i = 0, j = 0;
while (i < s.size() && j < value.size()) {
if (s.get(i) <= value.get(j)) {
s.add(s.get(i++));
} else {
s.add(value.get(j++));
}
}
while (i < s.size()) {
s.add(s.get(i++));
}
while (j < value.size()) {
s.add(value.get(j++));
}
return 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_v2(List<Integer> input, List<Integer> value) {
if (input == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> text = new ArrayList<>(input.size() + value.size());
int i = 0, j = 0;
while (i < input.size() && j < value.size()) {
if (input.get(i) <= value.get(j)) {
text.add(input.get(i++));
} else {
text.add(value.get(j++));
}
}
while (i < input.size()) {
text.add(input.get(i++));
}
while (j < value.size()) {
text.add(value.get(j++));
}
return text;
}
}
|
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> mergeSortedEx(List<Integer> value, List<Integer> s) {
if (value == null || s == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> n = new ArrayList<>(value.size() + s.size());
int i = 0, j = 0;
while (i < value.size() && j < s.size()) {
if (value.get(i) <= s.get(j)) {
n.add(value.get(i++));
} else {
n.add(s.get(j++));
}
}
while (i < value.size()) {
n.add(value.get(i++));
}
while (j < s.size()) {
n.add(s.get(j++));
}
return n;
}
}
|
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> list, List<Integer> text) {
if (list == null || text == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> arr = new ArrayList<>(list.size() + text.size());
int i = 0, j = 0;
while (i < list.size() && j < text.size()) {
if (list.get(i) <= text.get(j)) {
arr.add(list.get(i++));
} else {
arr.add(text.get(j++));
}
}
while (i < list.size()) {
arr.add(list.get(i++));
}
while (j < text.size()) {
arr.add(text.get(j++));
}
return 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> arr, List<Integer> input) {
if (arr == null || input == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> list = new ArrayList<>(arr.size() + input.size());
int i = 0, j = 0;
while (i < arr.size() && j < input.size()) {
if (arr.get(i) <= input.get(j)) {
list.add(arr.get(i++));
} else {
list.add(input.get(j++));
}
}
while (i < arr.size()) {
list.add(arr.get(i++));
}
while (j < input.size()) {
list.add(input.get(j++));
}
return list;
}
}
|
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> nums, List<Integer> value) {
if (nums == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> value = new ArrayList<>(nums.size() + value.size());
int i = 0, j = 0;
while (i < nums.size() && j < value.size()) {
if (nums.get(i) <= value.get(j)) {
value.add(nums.get(i++));
} else {
value.add(value.get(j++));
}
}
while (i < nums.size()) {
value.add(nums.get(i++));
}
while (j < value.size()) {
value.add(value.get(j++));
}
return value;
}
}
|
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> mergeSortedEx(List<Integer> value, List<Integer> list) {
if (value == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> text = new ArrayList<>(value.size() + list.size());
int i = 0, j = 0;
while (i < value.size() && j < list.size()) {
if (value.get(i) <= list.get(j)) {
text.add(value.get(i++));
} else {
text.add(list.get(j++));
}
}
while (i < value.size()) {
text.add(value.get(i++));
}
while (j < list.size()) {
text.add(list.get(j++));
}
return text;
}
}
|
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> n, List<Integer> str) {
if (n == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> s = new ArrayList<>(n.size() + str.size());
int i = 0, j = 0;
while (i < n.size() && j < str.size()) {
if (n.get(i) <= str.get(j)) {
s.add(n.get(i++));
} else {
s.add(str.get(j++));
}
}
while (i < n.size()) {
s.add(n.get(i++));
}
while (j < str.size()) {
s.add(str.get(j++));
}
return 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> n, List<Integer> value) {
if (n == null || value == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> n = new ArrayList<>(n.size() + value.size());
int i = 0, j = 0;
while (i < n.size() && j < value.size()) {
if (n.get(i) <= value.get(j)) {
n.add(n.get(i++));
} else {
n.add(value.get(j++));
}
}
while (i < n.size()) {
n.add(n.get(i++));
}
while (j < value.size()) {
n.add(value.get(j++));
}
return n;
}
}
|
java
|
function
|
medium
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide(int input, int nums) {
if (nums == 0) {
throw new IllegalArgumentException("nums must not be zero");
}
return (double) input / nums;
}
}
|
java
|
bug-fix
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_alt(int n, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) n / text;
}
}
|
java
|
bug-fix
|
easy
|
|
Write a Java method that reverses a string.
|
public class StringUtils {
public static String reverseString(String nums) {
if (nums == null) {
return null;
}
return new StringBuilder(nums).reverse().toString();
}
}
|
java
|
function
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divideEx(int list, int text) {
if (text == 0) {
throw new IllegalArgumentException("text must not be zero");
}
return (double) list / text;
}
}
|
java
|
bug-fix
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide_alt(int s, int nums) {
if (nums == 0) {
throw new IllegalArgumentException("nums must not be zero");
}
return (double) s / nums;
}
}
|
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 value) {
if (value == null) {
return 0;
}
int count = 0;
for (char c : value.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(c) >= 0) {
count++;
}
}
return count;
}
}
|
java
|
function
|
easy
|
|
Fix the following Java method so it avoids division by zero.
|
public class MathUtils {
public static double divide(int str, int arr) {
if (arr == 0) {
throw new IllegalArgumentException("arr must not be zero");
}
return (double) str / 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> mergeSortedEx(List<Integer> arr, List<Integer> str) {
if (arr == null || str == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> s = new ArrayList<>(arr.size() + str.size());
int i = 0, j = 0;
while (i < arr.size() && j < str.size()) {
if (arr.get(i) <= str.get(j)) {
s.add(arr.get(i++));
} else {
s.add(str.get(j++));
}
}
while (i < arr.size()) {
s.add(arr.get(i++));
}
while (j < str.size()) {
s.add(str.get(j++));
}
return 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_new(List<Integer> text, List<Integer> n) {
if (text == null || n == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str = new ArrayList<>(text.size() + n.size());
int i = 0, j = 0;
while (i < text.size() && j < n.size()) {
if (text.get(i) <= n.get(j)) {
str.add(text.get(i++));
} else {
str.add(n.get(j++));
}
}
while (i < text.size()) {
str.add(text.get(i++));
}
while (j < n.size()) {
str.add(n.get(j++));
}
return str;
}
}
|
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> arr, List<Integer> list) {
if (arr == null || list == null) {
throw new IllegalArgumentException("lists must not be null");
}
List<Integer> str = new ArrayList<>(arr.size() + list.size());
int i = 0, j = 0;
while (i < arr.size() && j < list.size()) {
if (arr.get(i) <= list.get(j)) {
str.add(arr.get(i++));
} else {
str.add(list.get(j++));
}
}
while (i < arr.size()) {
str.add(arr.get(i++));
}
while (j < list.size()) {
str.add(list.get(j++));
}
return str;
}
}
|
java
|
function
|
medium
|
|
Complete the following Java method so it returns the maximum value in an array.
|
public class ArrayUtils {
public static int max(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;
}
}
return max;
}
}
|
java
|
completion
|
easy
|
|
Write a Java method that reverses a string.
|
public class StringUtils {
public static String reverseString_v2(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 divide(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 checks whether a number is prime.
|
public class MathUtils {
public static boolean isPrime_new(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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.