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(int str, int str) { if (str == 0) { throw new IllegalArgumentException("str must not be zero"); } return (double) str / 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_v2(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
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_new(int input, int n) { if (n == 0) { throw new IllegalArgumentException("n must not be zero"); } return (double) input / 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> str, List<Integer> arr) { if (str == null || arr == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> n = 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)) { n.add(str.get(i++)); } else { n.add(arr.get(j++)); } } while (i < str.size()) { n.add(str.get(i++)); } while (j < arr.size()) { n.add(arr.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_v2(List<Integer> input, List<Integer> text) { if (input == null || text == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> s = new ArrayList<>(input.size() + text.size()); int i = 0, j = 0; while (i < input.size() && j < text.size()) { if (input.get(i) <= text.get(j)) { s.add(input.get(i++)); } else { s.add(text.get(j++)); } } while (i < input.size()) { s.add(input.get(i++)); } while (j < text.size()) { s.add(text.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> list, List<Integer> arr) { if (list == null || arr == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> n = new ArrayList<>(list.size() + arr.size()); int i = 0, j = 0; while (i < list.size() && j < arr.size()) { if (list.get(i) <= arr.get(j)) { n.add(list.get(i++)); } else { n.add(arr.get(j++)); } } while (i < list.size()) { n.add(list.get(i++)); } while (j < arr.size()) { n.add(arr.get(j++)); } return n; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideHelper(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 checks whether a number is prime.
public class MathUtils { public static boolean isPrimeHelper(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 checks whether a number is prime.
public class MathUtils { public static boolean isPrime_alt(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 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> mergeSortedEx(List<Integer> value, List<Integer> nums) { if (value == null || nums == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> list = new ArrayList<>(value.size() + nums.size()); int i = 0, j = 0; while (i < value.size() && j < nums.size()) { if (value.get(i) <= nums.get(j)) { list.add(value.get(i++)); } else { list.add(nums.get(j++)); } } while (i < value.size()) { list.add(value.get(i++)); } while (j < nums.size()) { list.add(nums.get(j++)); } return list; } }
java
function
medium
Write a Java method that reverses a string.
public class StringUtils { public static String reverseString_v2(String n) { if (n == null) { return null; } return new StringBuilder(n).reverse().toString(); } }
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide(int arr, int text) { if (text == 0) { throw new IllegalArgumentException("text must not be zero"); } return (double) arr / 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(List<Integer> input, List<Integer> nums) { if (input == null || nums == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> nums = new ArrayList<>(input.size() + nums.size()); int i = 0, j = 0; while (i < input.size() && j < nums.size()) { if (input.get(i) <= nums.get(j)) { nums.add(input.get(i++)); } else { nums.add(nums.get(j++)); } } while (i < input.size()) { nums.add(input.get(i++)); } while (j < nums.size()) { nums.add(nums.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(List<Integer> str, List<Integer> str) { if (str == null || str == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> nums = new ArrayList<>(str.size() + str.size()); int i = 0, j = 0; while (i < str.size() && j < str.size()) { if (str.get(i) <= str.get(j)) { nums.add(str.get(i++)); } else { nums.add(str.get(j++)); } } while (i < str.size()) { nums.add(str.get(i++)); } while (j < str.size()) { nums.add(str.get(j++)); } return nums; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideHelper(int list, int arr) { if (arr == 0) { throw new IllegalArgumentException("arr must not be zero"); } return (double) list / 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> str, List<Integer> nums) { if (str == null || nums == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> str = new ArrayList<>(str.size() + nums.size()); int i = 0, j = 0; while (i < str.size() && j < nums.size()) { if (str.get(i) <= nums.get(j)) { str.add(str.get(i++)); } else { str.add(nums.get(j++)); } } while (i < str.size()) { str.add(str.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_new(List<Integer> str, List<Integer> arr) { if (str == null || arr == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> nums = 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)) { nums.add(str.get(i++)); } else { nums.add(arr.get(j++)); } } while (i < str.size()) { nums.add(str.get(i++)); } while (j < arr.size()) { nums.add(arr.get(j++)); } return nums; } }
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 value) { if (value == 0) { throw new IllegalArgumentException("value must not be zero"); } return (double) input / 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_alt(List<Integer> text, List<Integer> str) { if (text == null || str == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> nums = 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)) { nums.add(text.get(i++)); } else { nums.add(str.get(j++)); } } while (i < text.size()) { nums.add(text.get(i++)); } while (j < str.size()) { nums.add(str.get(j++)); } return nums; } }
java
function
medium