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 reverses a string.
public class StringUtils { public static String reverseString_new(String n) { if (n == null) { return null; } return new StringBuilder(n).reverse().toString(); } }
java
function
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime(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
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrimeEx(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 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 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> str, List<Integer> value) { if (str == 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> mergeSortedHelper(List<Integer> str, List<Integer> str) { if (str == null || str == 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 text, int arr) { if (arr == 0) { throw new IllegalArgumentException("arr must not be zero"); } return (double) text / arr; } }
java
bug-fix
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int maxHelper(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;...
java
completion
easy
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels(String text) { if (text == null) { return 0; } int count = 0; for (char c : text.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } re...
java
function
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafeHelper(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 checks whether a number is prime.
public class MathUtils { public static boolean isPrimeEx(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 reverses a string.
public class StringUtils { public static String reverseString_v2(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 n, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) n / 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_alt(String nums) { if (nums == null) { return 0; } int count = 0; for (char c : nums.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } ...
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(String str) { try { return Integer.parseInt(str); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + str); 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 max_new(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
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafeHelper(String arr) { try { return Integer.parseInt(arr); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + arr); 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 max_alt(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
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_new(int value, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) value / nums; } }
java
bug-fix
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(int str, int input) { if (input == 0) { throw new IllegalArgumentException("input must not be zero"); } return (double) str / 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_alt(List<Integer> list, List<Integer> s) { if (list == null || s == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> te...
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_alt(int input, int n) { if (n == 0) { throw new IllegalArgumentException("n must not be zero"); } return (double) input / 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_v2(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
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowelsHelper(String n) { if (n == null) { return 0; } int count = 0; for (char c : n.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } retur...
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide(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 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> nums, List<Integer> value) { if (nums == null || value == null) { throw new IllegalArgumentException("lists must not be null"); } List<Inte...
java
function
medium
Write a Java method that reverses a string.
public class StringUtils { public static String reverseString_alt(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 reverseStringEx(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 reverseString_new(String value) { if (value == null) { return null; } return new StringBuilder(value).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 input) { try { return Integer.parseInt(input); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + input); 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 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 parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_new(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_alt(int arr, int list) { if (list == 0) { throw new IllegalArgumentException("list must not be zero"); } return (double) arr / 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> 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 checks whether a number is prime.
public class MathUtils { public static boolean isPrime_v2(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
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideHelper(int text, int value) { if (value == 0) { throw new IllegalArgumentException("value must not be zero"); } return (double) text / value; } }
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_alt(String value) { try { return Integer.parseInt(value); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + value); return 0; } } }
java
exception-handling
medium
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels_alt(String s) { if (s == null) { return 0; } int count = 0; for (char c : s.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return ...
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_new(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_v2(List<Integer> n, List<Integer> value) { if (n == null || value == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> v...
java
function
medium
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels_v2(String str) { if (str == null) { return 0; } int count = 0; for (char c : str.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } re...
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> arr, List<Integer> s) { if (arr == null || s == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> 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> mergeSortedHelper(List<Integer> arr, List<Integer> s) { if (arr == null || s == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> va...
java
function
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrimeHelper(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 reverses a string.
public class StringUtils { public static String reverseString(String text) { if (text == null) { return null; } return new StringBuilder(text).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_alt(List<Integer> s, List<Integer> value) { if (s == null || value == 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[] 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> mergeSorted_alt(List<Integer> text, List<Integer> input) { if (text == null || input == 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_new(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_new(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 counts the number of vowels in a string.
public class StringUtils { public static int countVowels(String list) { if (list == null) { return 0; } int count = 0; for (char c : list.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } re...
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> list, List<Integer> list) { if (list == 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> mergeSortedHelper(List<Integer> text, List<Integer> nums) { if (text == null || nums == 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(int nums, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) nums / 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_alt(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 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> text) { if (list == null || text == 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_new(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 counts the number of vowels in a string.
public class StringUtils { public static int countVowelsEx(String str) { if (str == null) { return 0; } int count = 0; for (char c : str.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } ret...
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(int list, int list) { if (list == 0) { throw new IllegalArgumentException("list must not be zero"); } return (double) list / 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_alt(String str) { if (str == null) { return 0; } int count = 0; for (char c : str.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } r...
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> s) { if (str == null || s == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> valu...
java
function
medium
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels_v2(String value) { if (value == null) { return 0; } int count = 0; for (char c : value.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 divide(int text, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) text / 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> mergeSortedHelper(List<Integer> text, List<Integer> input) { if (text == 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_alt(List<Integer> nums, List<Integer> str) { if (nums == null || str == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer...
java
function
medium
Write a Java method that reverses a string.
public class StringUtils { public static String reverseString_alt(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 countVowels(String nums) { if (nums == null) { return 0; } int count = 0; for (char c : nums.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } re...
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(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 reverses a string.
public class StringUtils { public static String reverseStringHelper(String n) { if (n == null) { return null; } return new StringBuilder(n).reverse().toString(); } }
java
function
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrimeEx(int text) { if (text < 2) { return false; } for (int i = 2; i * i <= text; i++) { if (text % 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> text, List<Integer> str) { if (text == null || str == 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> mergeSortedEx(List<Integer> s, List<Integer> value) { if (s == null || value == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> te...
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> n, List<Integer> n) { if (n == 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 divideEx(int list, int input) { if (input == 0) { throw new IllegalArgumentException("input must not be zero"); } return (double) list / 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_alt(List<Integer> value, List<Integer> input) { if (value == 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_new(List<Integer> input, List<Integer> nums) { if (input == null || nums == null) { throw new IllegalArgumentException("lists must not be null"); } List<Int...
java
function
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_v2(int text) { if (text < 2) { return false; } for (int i = 2; i * i <= text; i++) { if (text % 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_new(int list, int str) { if (str == 0) { throw new IllegalArgumentException("str must not be zero"); } return (double) list / str; } }
java
bug-fix
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide(int s, int text) { if (text == 0) { throw new IllegalArgumentException("text must not be zero"); } return (double) s / text; } }
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 input) { if (input == null) { return 0; } int count = 0; for (char c : input.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 divide_v2(int arr, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) arr / 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> mergeSortedEx(List<Integer> s, List<Integer> s) { if (s == null || s == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> text = new...
java
function
medium
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels_v2(String arr) { if (arr == null) { return 0; } int count = 0; for (char c : arr.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } re...
java
function
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_v2(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 checks whether a number is prime.
public class MathUtils { public static boolean isPrime(int text) { if (text < 2) { return false; } for (int i = 2; i * i <= text; i++) { if (text % 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> text, List<Integer> list) { if (text == null || list == 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 parseIntSafeHelper(String value) { try { return Integer.parseInt(value); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + value); 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_alt(List<Integer> input, List<Integer> nums) { if (input == null || nums == 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_v2(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 reverses a string.
public class StringUtils { public static String reverseString_alt(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_alt(int text, int value) { if (value == 0) { throw new IllegalArgumentException("value must not be zero"); } return (double) text / value; } }
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[] 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_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
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_alt(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) { 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_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
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringHelper(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 divideEx(int s, int arr) { if (arr == 0) { throw new IllegalArgumentException("arr must not be zero"); } return (double) s / arr; } }
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 arr) { if (arr == 0) { throw new IllegalArgumentException("arr must not be zero"); } return (double) value / 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 parseIntSafe(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 counts the number of vowels in a string.
public class StringUtils { public static int countVowels_alt(String value) { if (value == null) { return 0; } int count = 0; for (char c : value.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } ...
java
function
easy