code
stringlengths
160
48.7k
prompt
stringlengths
55
1.51k
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Check if in given list of numbers, are any two numbers closer to each other than given threshold. >>> hasCloseElements(Arrays.asList(1.0, 2.0, 3.0), 0.5) false >>> hasCloseElements(...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Check if in given list of numbers, are any two numbers closer to each other than given threshold. >>> hasCloseElements(Arrays.asList(1.0, 2.0, 3.0), 0.5) false >>> hasCloseElements(Arrays.asList(...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Input to this function is a string containing multiple groups of nested parentheses. Your goal is to separate those group into separate strings and return the list of those. Separate gr...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Input to this function is a string containing multiple groups of nested parentheses. Your goal is to separate those group into separate strings and return the list of those. Separate groups are balan...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). R...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). Return the deci...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account fallls below zero, an...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account fallls below zero, and at that ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** For a given list of input numbers, calculate Mean Absolute Deviation around the mean of this dataset. Mean Absolute Deviation is the average absolute difference between each element...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** For a given list of input numbers, calculate Mean Absolute Deviation around the mean of this dataset. Mean Absolute Deviation is the average absolute difference between each element and a centerp...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Insert a number 'delimeter' between every two consecutive elements of input list `numbers' >>> intersperse(List.of(), 4) [] >>> intersperse(Arrays.asList(1, 2, 3), 4) [1, 4, 2, ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Insert a number 'delimeter' between every two consecutive elements of input list `numbers' >>> intersperse(List.of(), 4) [] >>> intersperse(Arrays.asList(1, 2, 3), 4) [1, 4, 2, 4, 3] */ ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has m...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Filter an input list of strings only for ones that contain given substring >>> filterBySubstring(List.of(), "a") [] >>> filterBySubstring(Arrays.asList("abc", "bacd", "cde", "array"...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Filter an input list of strings only for ones that contain given substring >>> filterBySubstring(List.of(), "a") [] >>> filterBySubstring(Arrays.asList("abc", "bacd", "cde", "array"), "a") ["...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. Empty sum should be equal to 0 and empty product should be equal to 1. >>> ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. Empty sum should be equal to 0 and empty product should be equal to 1. >>> sumProduct(Lis...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> rollingMax(Arrays.asList(1, 2, 3, 2, 3, 4, 2)) [1, 2, 3, 3, 3...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> rollingMax(Arrays.asList(1, 2, 3, 2, 3, 4, 2)) [1, 2, 3, 3, 3, 4, 4] *...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Test if given string is a palindrome */ public boolean isPalindrome(String string) { int i = 0; int j = string.length() - 1; while (i < j) { if (str...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Test if given string is a palindrome */ public boolean isPalindrome(String string) { int i = 0; int j = string.length() - 1; while (i < j) { if (string.charAt(i)!...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. >>> stringXor("010", "110") "100" */ publ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. >>> stringXor("010", "110") "100" */ public String stri...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> longest(List.of()) ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> longest(List.of()) Optional.e...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return a greatest common divisor of two integers a and b >>> greatestCommonDivisor(3, 5) 1 >>> greatestCommonDivisor(25, 15) 5 */ public int greatestCommonDivisor(int a...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return a greatest common divisor of two integers a and b >>> greatestCommonDivisor(3, 5) 1 >>> greatestCommonDivisor(25, 15) 5 */ public int greatestCommonDivisor(int a, int b) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return list of all prefixes from shortest to longest of the input string >>> allPrefixes("abc") ["a", "ab", "abc"] */ public List<String> allPrefixes(String string) { List<Stri...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return list of all prefixes from shortest to longest of the input string >>> allPrefixes("abc") ["a", "ab", "abc"] */ public List<String> allPrefixes(String string) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return a string containing space-delimited numbers starting from 0 upto n inclusive. >>> stringSequence(0) "0" >>> stringSequence(5) "0 1 2 3 4 5" */ public String stri...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return a string containing space-delimited numbers starting from 0 upto n inclusive. >>> stringSequence(0) "0" >>> stringSequence(5) "0 1 2 3 4 5" */ public String stringSequence(int...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given a string, find out how many distinct characters (regardless of case) does it consist of >>> countDistinctCharacters("xyzXYZ") 3 >>> countDistinctCharacters("Jerry") 4 ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given a string, find out how many distinct characters (regardless of case) does it consist of >>> countDistinctCharacters("xyzXYZ") 3 >>> countDistinctCharacters("Jerry") 4 */ public...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does e...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not la...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Find how many times a given substring can be found in the original string. Count overlaping cases. >>> howManyTimes("", "a") 0 >>> howManyTimes("aaa", "a") 3 >>> howManyTime...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Find how many times a given substring can be found in the original string. Count overlaping cases. >>> howManyTimes("", "a") 0 >>> howManyTimes("aaa", "a") 3 >>> howManyTimes("aaaa", "aa"...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the str...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbe...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** From a supplied list of numbers (of length at least two) select and return two that are the closest to each other and return them in order (smaller number, larger number). >>> findClose...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** From a supplied list of numbers (of length at least two) select and return two that are the closest to each other and return them in order (smaller number, larger number). >>> findClosestElements(Arr...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given list of numbers (of at least two elements), apply a linear transform to that list, such that the smallest number will become 0 and the largest will become 1 >>> rescaleToUnit(Arra...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given list of numbers (of at least two elements), apply a linear transform to that list, such that the smallest number will become 0 and the largest will become 1 >>> rescaleToUnit(Arrays.asList(1.0,...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Filter given list of any values only for integers >>> filter_integers(Arrays.asList('a', 3.14, 5)) [5] >>> filter_integers(Arrays.asList(1, 2, 3, "abc", Map.of(), List.of())) [1...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Filter given list of any values only for integers >>> filter_integers(Arrays.asList('a', 3.14, 5)) [5] >>> filter_integers(Arrays.asList(1, 2, 3, "abc", Map.of(), List.of())) [1, 2, 3] *...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return length of given string >>> strlen("") 0 >>> strlen("abc") 3 */ public int strlen(String string) { return string.length(); } } ``` Hope this helps!
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return length of given string >>> strlen("") 0 >>> strlen("abc") 3 */ public int strlen(String string) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** For a given number n, find the largest number that divides n evenly, smaller than n >>> largestDivisor(15) 5 */ public int largestDivisor(int n) { for (int i = n - 1; i > 0; i-...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** For a given number n, find the largest number that divides n evenly, smaller than n >>> largestDivisor(15) 5 */ public int largestDivisor(int n) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return list of prime factors of given integer in the order from smallest to largest. Each of the factors should be listed number of times corresponding to how many times it appeares in fact...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return list of prime factors of given integer in the order from smallest to largest. Each of the factors should be listed number of times corresponding to how many times it appeares in factorization. ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** From a list of integers, remove all elements that occur more than once. Keep order of elements left the same as in the input. >>> removeDuplicates(Ar...
Create Java method to complete this class: import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** From a list of integers, remove all elements that occur more than once. Keep order of elements left the same as in the input. >>> removeDuplicates(Array.asList(1, ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** For a given string, flip lowercase characters to uppercase and uppercase to lowercase. >>> flipCase("Hello") "hELLO" */ public String flipCase(String string) { StringBuilder sb...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** For a given string, flip lowercase characters to uppercase and uppercase to lowercase. >>> flipCase("Hello") "hELLO" */ public String flipCase(String string) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Concatenate list of strings into a single string >>> concatenate(List.of()) "" >>> concatenate(Arrays.asList("a", "b", "c")) "abc" */ public String concatenate(List<Str...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Concatenate list of strings into a single string >>> concatenate(List.of()) "" >>> concatenate(Arrays.asList("a", "b", "c")) "abc" */ public String concatenate(List<String> strings) ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** Filter an input list of strings only for ones that start with a given prefix. >>> filterByPrefix(List.of(), "a") [] >>> filterByPrefix(Arrays.asL...
Create Java method to complete this class: import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** Filter an input list of strings only for ones that start with a given prefix. >>> filterByPrefix(List.of(), "a") [] >>> filterByPrefix(Arrays.asList("abc", "bc...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** Return only positive numbers in the list. >>> getPositive(Arrays.asList(-1, 2, -4, 5, 6)) [2, 5, 6] >>> getPositive(Arrays.asList(5, 3, -5, 2, -3...
Create Java method to complete this class: import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** Return only positive numbers in the list. >>> getPositive(Arrays.asList(-1, 2, -4, 5, 6)) [2, 5, 6] >>> getPositive(Arrays.asList(5, 3, -5, 2, -3, 3, 9, 0, 123...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return true if a given number is prime, and false otherwise. >>> isPrime(6) false >>> isPrime(101) true >>> isPrime(11) true >>> isPrime(13441) true >>> isPr...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return true if a given number is prime, and false otherwise. >>> isPrime(6) false >>> isPrime(101) true >>> isPrime(11) true >>> isPrime(13441) true >>> isPrime(61) tr...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n */ public double poly(List<Double> xs, double x) { double re...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n */ public double poly(List<Double> xs, double x) { double result = 0; ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** This function takes a list l and returns a list l' such that l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by thr...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** This function takes a list l and returns a list l' such that l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return sorted unique elements in a list >>> unique(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123)) [0, 2, 3, 5, 9, 123] */ public List<Integer> unique(List<Integer> l) { List<Integ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return sorted unique elements in a list >>> unique(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123)) [0, 2, 3, 5, 9, 123] */ public List<Integer> unique(List<Integer> l) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return maximum element in the list. >>> maxElement(Arrays.asList(1, 2, 3)) 3 >>> maxElement(Arrays.asList(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10)) 123 */ public int maxE...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return maximum element in the list. >>> maxElement(Arrays.asList(1, 2, 3)) 3 >>> maxElement(Arrays.asList(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10)) 123 */ public int maxElement(List<In...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13. >>> fizzBuzz(50) 0 >>> fizzBuzz(78) 2 >>> fizzBuzz(79) 3 */ ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13. >>> fizzBuzz(50) 0 >>> fizzBuzz(78) 2 >>> fizzBuzz(79) 3 */ public int...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** This function takes a list l and returns a list l' such that l' is identical to l in the odd indicies, while its values at the even indicies are equal to the values of the even indicies...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** This function takes a list l and returns a list l' such that l' is identical to l in the odd indicies, while its values at the even indicies are equal to the values of the even indicies of l, but sor...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** returns encoded string by cycling groups of three characters. */ public String encodeCyclic(String s) { // split string to groups. Each of length 3. List<String> groups...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** returns encoded string by cycling groups of three characters. */ public String encodeCyclic(String s) { // split string to groups. Each of length 3. List<String> groups = new ArrayLi...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** primeFib returns n-th number that is a Fibonacci number and it's also prime. >>> primeFib(1) 2 >>> primeFib(2) 3 >>> primeFib(3) 5 >>> primeFib(4) 13 >>> pri...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** primeFib returns n-th number that is a Fibonacci number and it's also prime. >>> primeFib(1) 2 >>> primeFib(2) 3 >>> primeFib(3) 5 >>> primeFib(4) 13 >>> primeFib(5) 8...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** triplesSumToZero takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise. >>> triplesSumToZero(...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** triplesSumToZero takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise. >>> triplesSumToZero(Arrays.asList(...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets o...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start o...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** Return list with elements incremented by 1. >>> incrList(Arrays.asList(1, 2, 3)) [2, 3, 4] >>> incrList(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123...
Create Java method to complete this class: import java.util.*; import java.lang.*; import java.util.stream.Collectors; class Solution { /** Return list with elements incremented by 1. >>> incrList(Arrays.asList(1, 2, 3)) [2, 3, 4] >>> incrList(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123)) [6, 4, ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** pairsSumToZero takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False otherwise. >>> pairsSumToZero(Arrays....
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** pairsSumToZero takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False otherwise. >>> pairsSumToZero(Arrays.asList(1, 3, 5...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Change numerical base of input number x to base. return string representation after the conversion. base numbers are less than 10. >>> changeBase(8, 3) "22" >>> changeBase(8...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Change numerical base of input number x to base. return string representation after the conversion. base numbers are less than 10. >>> changeBase(8, 3) "22" >>> changeBase(8, 2) "1000...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given length of a side and high return area for a triangle. >>> triangleArea(5, 3) 7.5 */ public double triangleArea(double a, double h) { return a * h / 2; } } ``` Hope t...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given length of a side and high return area for a triangle. >>> triangleArea(5, 3) 7.5 */ public double triangleArea(double a, double h) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fib4(0) -> 0 fib4(1) -> 0 fib4(2) -> 2 fib4(3) -> 0 fib4(n) -> fib4(n-1)...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fib4(0) -> 0 fib4(1) -> 0 fib4(2) -> 2 fib4(3) -> 0 fib4(n) -> fib4(n-1) + fib4(n-2) +...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return median of elements in the list l. >>> median(Arrays.asList(3, 1, 2, 4, 5)) 3 >>> median(Arrays.asList(-10, 4, 6, 1000, 10, 20)) 15.0 */ public double median(List...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return median of elements in the list l. >>> median(Arrays.asList(3, 1, 2, 4, 5)) 3 >>> median(Arrays.asList(-10, 4, 6, 1000, 10, 20)) 15.0 */ public double median(List<Integer> l) {...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Checks if given string is a palindrome >>> isPalindrome("") true >>> isPalindrome("aba") true >>> isPalindrome("aaaaa") true >>> isPalindrome("zbcd") false ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Checks if given string is a palindrome >>> isPalindrome("") true >>> isPalindrome("aba") true >>> isPalindrome("aaaaa") true >>> isPalindrome("zbcd") false */ public ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return 2^n modulo p (be aware of numerics). >>> modp(3, 5) 3 >>> modp(1101, 101) 2 >>> modp(0, 101) 1 >>> modp(3, 11) 8 >>> modp(100, 101) 1 */ ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return 2^n modulo p (be aware of numerics). >>> modp(3, 5) 3 >>> modp(1101, 101) 2 >>> modp(0, 101) 1 >>> modp(3, 11) 8 >>> modp(100, 101) 1 */ public int mod...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** returns encoded string by shifting every character by 5 in the alphabet. */ public String encodeShift(String s) { StringBuilder sb = new StringBuilder(); for (char ch :...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** returns encoded string by shifting every character by 5 in the alphabet. */ public String encodeShift(String s) { StringBuilder sb = new StringBuilder(); for (char ch : s.toCharArray...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** removeVowels is a function that takes string and returns string without vowels. >>> removeVowels("") "" >>> removeVowels("abcdef\nghijklm") "bcdf\nghjklm" >>> removeVowels("...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** removeVowels is a function that takes string and returns string without vowels. >>> removeVowels("") "" >>> removeVowels("abcdef\nghijklm") "bcdf\nghjklm" >>> removeVowels("abcdef") "...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return True if all numbers in the list l are below threshold t. >>> belowThreshold(Arrays.asList(1, 2, 4, 10), 100) true >>> belowThreshold(Arrays.asList(1, 20, 4, 10), 5) false...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return True if all numbers in the list l are below threshold t. >>> belowThreshold(Arrays.asList(1, 2, 4, 10), 100) true >>> belowThreshold(Arrays.asList(1, 20, 4, 10), 5) false */ p...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Add two numbers x and y >>> add(2, 3) 5 >>> add(5, 7) 12 */ public int add(int x, int y) { return x + y; } } ``` Hope this helps!
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Add two numbers x and y >>> add(2, 3) 5 >>> add(5, 7) 12 */ public int add(int x, int y) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Check if two words have the same characters. >>> sameChars("eabcdzzzz", "dddzzzzzzzddeddabc") true >>> sameChars("abcd", "dddddddabc") true >>> sameChars("dddddddabc", "abcd...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Check if two words have the same characters. >>> sameChars("eabcdzzzz", "dddzzzzzzzddeddabc") true >>> sameChars("abcd", "dddddddabc") true >>> sameChars("dddddddabc", "abcd") true ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return n-th Fibonacci number. >>> fib(10) 55 >>> fib(1) 1 >>> fib(8) 21 */ public int fib(int n) { if (n == 0) { return 0; } if (n =...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return n-th Fibonacci number. >>> fib(10) 55 >>> fib(1) 1 >>> fib(8) 21 */ public int fib(int n) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** brackets is a string of "<" and ">". return True if every opening bracket has a corresponding closing bracket. >>> correctBracketing("<") false >>> correctBracketing("<>") ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** brackets is a string of "<" and ">". return True if every opening bracket has a corresponding closing bracket. >>> correctBracketing("<") false >>> correctBracketing("<>") true >...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return True is list elements are monotonically increasing or decreasing. >>> monotonic(Arrays.asList(1, 2, 4, 20)) true >>> monotonic(Arrays.asList(1, 20, 4, 10)) false >>> ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return True is list elements are monotonically increasing or decreasing. >>> monotonic(Arrays.asList(1, 2, 4, 20)) true >>> monotonic(Arrays.asList(1, 20, 4, 10)) false >>> monotonic(Arra...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return sorted unique common elements for two lists. >>> common(Arrays.asList(1, 4, 3, 34, 653, 2, 5), Arrays.asList(5, 7, 1, 5, 9, 653, 121)) [1, 5, 653] >>> common(Arrays.asList(5,...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return sorted unique common elements for two lists. >>> common(Arrays.asList(1, 4, 3, 34, 653, 2, 5), Arrays.asList(5, 7, 1, 5, 9, 653, 121)) [1, 5, 653] >>> common(Arrays.asList(5, 3, 2, 8), Arr...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Return the largest prime factor of n. Assume n > 1 and is not a prime. >>> largestPrimeFactor(13195) 29 >>> largestPrimeFactor(2048) 2 */ public int largestPrimeFactor(...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Return the largest prime factor of n. Assume n > 1 and is not a prime. >>> largestPrimeFactor(13195) 29 >>> largestPrimeFactor(2048) 2 */ public int largestPrimeFactor(int n) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** sumToN is a function that sums numbers from 1 to n. >>> sumToN(30) 465 >>> sumToN(100) 5050 >>> sumToN(5) 15 >>> sumToN(10) 55 >>> sumToN(1) 1 */ ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** sumToN is a function that sums numbers from 1 to n. >>> sumToN(30) 465 >>> sumToN(100) 5050 >>> sumToN(5) 15 >>> sumToN(10) 55 >>> sumToN(1) 1 */ public int s...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** brackets is a string of "(" and ")". return True if every opening bracket has a corresponding closing bracket. >>> correctBracketing("(") false >>> correctBracketing("()") ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** brackets is a string of "(" and ")". return True if every opening bracket has a corresponding closing bracket. >>> correctBracketing("(") false >>> correctBracketing("()") true >>> c...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** xs represent coefficients of a polynomial. xs[0] + xs[1] * x + xs[2] * x^2 + .... Return derivative of this polynomial in the same form. >>> derivative(Arrays.asList(3, 1, 2, 4, 5)...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** xs represent coefficients of a polynomial. xs[0] + xs[1] * x + xs[2] * x^2 + .... Return derivative of this polynomial in the same form. >>> derivative(Arrays.asList(3, 1, 2, 4, 5)) [1, 4, 1...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fi...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fi...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function vowelsCount which takes a string representing a word as input and returns the number of vowels in the string. Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y'...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function vowelsCount which takes a string representing a word as input and returns the number of vowels in the string. Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Circular shift the digits of the integer x, shift the digits right by shift and return the result as a string. If shift > number of digits, return digits reversed. >>> circularShift...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Circular shift the digits of the integer x, shift the digits right by shift and return the result as a string. If shift > number of digits, return digits reversed. >>> circularShift(12, 1) "2...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a string as input and returns the sum of the upper characters only' ASCII codes. Examples: digitSum("") => 0 digitSum("abAB") => 131 ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a string as input and returns the sum of the upper characters only' ASCII codes. Examples: digitSum("") => 0 digitSum("abAB") => 131 digitSum("abc...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** In this task, you will be given a string that represents a number of apples and oranges that are distributed in a basket of fruit this basket contains apples, oranges, and mango fruits....
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** In this task, you will be given a string that represents a number of apples and oranges that are distributed in a basket of fruit this basket contains apples, oranges, and mango fruits. Given the str...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** "Given an array representing a branch of a tree that has non-negative integer nodes your task is to pluck one of the nodes and return it. The plucked node should be the node with the sm...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** "Given an array representing a branch of a tree that has non-negative integer nodes your task is to pluck one of the nodes and return it. The plucked node should be the node with the smallest even va...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You are given a non-empty list of positive integers. Return the greatest integer that is greater than zero, and has a frequency greater than or equal to the value of the integer itself. ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You are given a non-empty list of positive integers. Return the greatest integer that is greater than zero, and has a frequency greater than or equal to the value of the integer itself. The frequency...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given list of integers, return list in strange order. Strange sorting, is when you start with the minimum value, then maximum of the remaining integers, then minimum and so on. Exa...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given list of integers, return list in strange order. Strange sorting, is when you start with the minimum value, then maximum of the remaining integers, then minimum and so on. Examples: str...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points if the three sides form a valid triangle. Otherwise return -1 Three s...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points if the three sides form a valid triangle. Otherwise return -1 Three sides make a va...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that returns True if the object q will fly, and False otherwise. The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that returns True if the object q will fly, and False otherwise. The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the m...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given an array arr of integers, find the minimum number of elements that need to be changed to make the array palindromic. A palindromic array is an array that is read the same backward...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given an array arr of integers, find the minimum number of elements that need to be changed to make the array palindromic. A palindromic array is an array that is read the same backwards and forwards...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that accepts two lists of strings and returns the list that has total number of chars in the all strings of the list less than the other list. if the two lists have th...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that accepts two lists of strings and returns the list that has total number of chars in the all strings of the list less than the other list. if the two lists have the same number ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that returns true if the given number is the multiplication of 3 prime numbers and false otherwise. Knowing that (a) is less then 100. Example: isMultiplyPrime(...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that returns true if the given number is the multiplication of 3 prime numbers and false otherwise. Knowing that (a) is less then 100. Example: isMultiplyPrime(30) == true ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Your task is to write a function that returns true if a number x is a simple power of n and false in other cases. x is a simple power of n if n**int=x For example: isSimplePower...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Your task is to write a function that returns true if a number x is a simple power of n and false in other cases. x is a simple power of n if n**int=x For example: isSimplePower(1, 4) => true...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that takes an integer a and returns true if this ingeger is a cube of some integer number. Note: you may assume the input is always valid. Examples: iscube(1) =...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that takes an integer a and returns true if this ingeger is a cube of some integer number. Note: you may assume the input is always valid. Examples: iscube(1) ==> true is...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You have been tasked to write a function that receives a hexadecimal number as a string and counts the number of hexadecimal digits that are primes (prime number, or a prime, is a natur...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You have been tasked to write a function that receives a hexadecimal number as a string and counts the number of hexadecimal digits that are primes (prime number, or a prime, is a natural number ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You will be given a number in decimal form and your task is to convert it to binary format. The function should return a string, with each character representing a binary number. Each c...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You will be given a number in decimal form and your task is to convert it to binary format. The function should return a string, with each character representing a binary number. Each character in th...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You are given a string s. Your task is to check if the string is happy or not. A string is happy if its length is at least 3 and every 3 consecutive letters are distinct For example...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You are given a string s. Your task is to check if the string is happy or not. A string is happy if its length is at least 3 and every 3 consecutive letters are distinct For example: isHappy(...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** It is the last week of the semester and the teacher has to give the grades to students. The teacher has been making her own algorithm for grading. The only problem is, she has lost the ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** It is the last week of the semester and the teacher has to give the grades to students. The teacher has been making her own algorithm for grading. The only problem is, she has lost the code she used ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a string and returns true if the string length is a prime number or false otherwise Examples primeLength("Hello") == true primeLength("abcdcba") == t...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a string and returns true if the string length is a prime number or false otherwise Examples primeLength("Hello") == true primeLength("abcdcba") == true primeL...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given a positive integer n, return the count of the numbers of n-digit positive integers that start or end with 1. */ public int startsOneEnds(int n) { if (n == 1) { re...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given a positive integer n, return the count of the numbers of n-digit positive integers that start or end with 1. */ public int startsOneEnds(int n) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given a positive integer N, return the total sum of its digits in binary. Example For N = 1000, the sum of digits will be 1 the output should be "1". For N = 150, the sum o...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given a positive integer N, return the total sum of its digits in binary. Example For N = 1000, the sum of digits will be 1 the output should be "1". For N = 150, the sum of digits will ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given a non-empty list of integers lst. add the even elements that are at odd indices.. Examples: add(Arrays.asList(4, 2, 6, 7)) ==> 2 */ public int add(List<Integer> lst)...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given a non-empty list of integers lst. add the even elements that are at odd indices.. Examples: add(Arrays.asList(4, 2, 6, 7)) ==> 2 */ public int add(List<Integer> lst) {
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a string and returns an ordered version of it. Ordered version of string, is a string where all words (separated by space) are replaced by a new word where a...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a string and returns an ordered version of it. Ordered version of string, is a string where all words (separated by space) are replaced by a new word where all the charact...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You are given a 2 dimensional data, as a nested lists, which is similar to matrix, however, unlike matrices, each row may contain a different number of columns. Given lst, and integ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You are given a 2 dimensional data, as a nested lists, which is similar to matrix, however, unlike matrices, each row may contain a different number of columns. Given lst, and integer x, find int...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given an array of non-negative integers, return a copy of the given array after sorting, you will sort the given array in ascending order if the sum( first index value, last index value) is...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given an array of non-negative integers, return a copy of the given array after sorting, you will sort the given array in ascending order if the sum( first index value, last index value) is odd, or s...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Create a function encrypt that takes a string as an argument and returns a string encrypted with the alphabet being rotated. The alphabet should be rotated in a manner such that the let...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Create a function encrypt that takes a string as an argument and returns a string encrypted with the alphabet being rotated. The alphabet should be rotated in a manner such that the letters shift...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You are given a list of integers. Write a function nextSmallest() that returns the 2nd smallest element of the list. Return null if there is no such element. <p> nextSmallest(Ar...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You are given a list of integers. Write a function nextSmallest() that returns the 2nd smallest element of the list. Return null if there is no such element. <p> nextSmallest(Arrays.asList(1,...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You'll be given a string of words, and your task is to count the number of boredoms. A boredom is a sentence that starts with the word "I". Sentences are delimited by '.', '?' or '!'. ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You'll be given a string of words, and your task is to count the number of boredoms. A boredom is a sentence that starts with the word "I". Sentences are delimited by '.', '?' or '!'. For exampl...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Create a function that takes 3 numbers. Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. Returns false in any other cases. Exa...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Create a function that takes 3 numbers. Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. Returns false in any other cases. Examples anyI...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a message, and encodes in such a way that it swaps case of all letters, replaces all vowels in the message with the letter that appears 2 places ahead of tha...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Write a function that takes a message, and encodes in such a way that it swaps case of all letters, replaces all vowels in the message with the letter that appears 2 places ahead of that vowel in...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** You are given a list of integers. You need to find the largest prime value and return the sum of its digits. Examples: For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** You are given a list of integers. You need to find the largest prime value and return the sum of its digits. Examples: For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output s...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given a map, return True if all keys are strings in lower case or all keys are strings in upper case, else return False. The function should return False is the given map is empty. ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given a map, return True if all keys are strings in lower case or all keys are strings in upper case, else return False. The function should return False is the given map is empty. Examples: ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Implement a function that takes an non-negative integer and returns an array of the first n integers that are prime numbers and less than n. for example: countUpTo(5) => [2,3] c...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Implement a function that takes an non-negative integer and returns an array of the first n integers that are prime numbers and less than n. for example: countUpTo(5) => [2,3] countUpTo(11) =...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Complete the function that takes two integers and returns the product of their unit digits. Assume the input is always valid. Examples: multiply(148, 412) should return 16. ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Complete the function that takes two integers and returns the product of their unit digits. Assume the input is always valid. Examples: multiply(148, 412) should return 16. multiply(19, 2...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Given a string s, count the number of uppercase vowels in even indices. For example: countUpper("aBCdEf") returns 1 countUpper("abcdefg") returns 0 countUpper("dBBE") retur...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Given a string s, count the number of uppercase vowels in even indices. For example: countUpper("aBCdEf") returns 1 countUpper("abcdefg") returns 0 countUpper("dBBE") returns 0 */ ...
Of course, here is the Java code you requested: ```java import java.util.*; import java.lang.*; class Solution { /** Create a function that takes a value (string) representing a number and returns the closest integer to it. If the number is equidistant from two integers, round it away from zero. ...
Create Java method to complete this class: import java.util.*; import java.lang.*; class Solution { /** Create a function that takes a value (string) representing a number and returns the closest integer to it. If the number is equidistant from two integers, round it away from zero. Examples >...