Complete these stages of code public class Question1 { //begin class /** * * @param list * @return the number of values

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Complete these stages of code public class Question1 { //begin class /** * * @param list * @return the number of values

Post by answerhappygod »

Complete these stages of code
public class Question1 { //begin class
/**
*
* @param list
* @return the number of values that are even in
the list
* return 0 if list is null or empty
*/
public static int countEven(ArrayList<Integer> list) {
return 0;
}
/**
* @param n: assumed to be more than 0
* @param d, d >= 0 and d <= 9
* @return true if number n contains the digit
d, false otherwise
* you may assume that 0 itself doesn't contain ANY digit (not
even 0)
* NOTE: This method must be implemented recursively.
* hint: n%10 gives the last digit, n/10 gives the rest of
the number
*/
public static boolean containsDigitRecursive(int n, int d) {
return false;
}
/**
* @param list
* @return the sum of differences between even
and odd indices.
* return 0 if list is null
* for example,
* if list = [20, 50, 80, 60, 30], return
(20+80+30)-(50+60)=20
* if list = [20, 30], return -10
* if list = [40], return 40
*/
public static int
differenceEvenOddIndices(ArrayList<Integer> list) {
return 0;
}
/**
* @param str: assume it's not null
* @return the string with all spaces
removed
* for example,
* if str = "voila", return voila"
* if str = " a b c
d . ", return "abcd."
* if str = "", return ""
*/
public static String withoutSpacesRecursive(String str) {
if(str.isEmpty())
return"";
if(str.charAt(0) == ' ')
return withoutSpacesRecursive(str.substring(1));
return str.charAt(0) +
withoutSpacesRecursive(str.substring(1));
}
public class Question5 { //begin class
/**
* @param list1
* @param list2
* @return true if the two lists are mutually
reverse of each other, false otherwise
*/
public static boolean
areMutuallyReverse(ArrayList<Integer> list1,
ArrayList<Integer> list2) {
return false;
}
/**
* @param list
* @return reverse of the list
*/
public static ArrayList<Integer>
reverse(ArrayList<Integer> list) {
return"";
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply