Exercises from previous exams ------------------------------ Ex.1 --- Write a subroutine takes a string as argument and returns the sum of the digits 0-9 that appear in the string, ignoring all other characters. The subroutine returns 0 if there are no digits in the string. Note that Character.isDigit(c) tests if a character c is one of the characters '0', '1', .. '9' and Integer.parseInt(string) converts a string to an integer. Remember to check the corner cases! The subroutine should always return a value and not crash. Examples: sumDigits("aa1bc2d3") ==> 6 sumDigits("aa11b33") ==> 8 sumDigits("Chocolate") ==> 0 Ex.2 ----- Write a subroutine takes as argument an array of integers and returns an array that is left shifted by one -- so {6, 2, 5, 3} returns {2, 5, 3, 6}. You may modify and return the given array, or return a new array. Remember to check the corner cases! The subroutine should always return a value and not crash. Examples: shiftLeft({6, 2, 5, 3}) -> {2, 5, 3, 6} shiftLeft({1, 2}) -> {2, 1} shiftLeft({1}) -> {1} Ex.3 ---- Write a subroutine takes as argument start and end integers, and returns a new array containing the sequence of integers from start up to but not including end. For insstance, start=5 and end=10 yields the array {5, 6, 7, 8, 9}. You can assume the end number is greater or equal to the start number. Note that an array of length 0 is also a valid aray. Examples: fizzArray3(5, 10) -> {5, 6, 7, 8, 9} fizzArray3(11, 18) -> {11, 12, 13, 14, 15, 16, 17} fizzArray3(1, 3) -> {1, 2} fizzArray3(1, 1) -> {} Ex.4 ---- Write a subroutine taking an array of integers as argument, returning true if that array contains three consecutive adjacent numbers, such as 4, 5, 6, or 23, 24, 25. Remember to check the corner cases! The subroutine should always return a value, and not crash. Examples: threeConsecutive({1, 4, 5, 6, 2}) ==> true threeConsecutive({1, 2, 3}) ==> true threeConsecutive({1, 2, 4}) ==> false threeConsecutive({1, 2, 4, 5}) ==> false Ex.5 (not from an exam :) -------------------------- Sandy likes palindromes. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as it does forward. For example, madam is a palindrome. On her 7-th birthday, Sandy's uncle, Richie Rich, offered her an n-digit check which she refused because the number was not a palindrome. Richie then challenged Sandy to make the number palindromic by changing no more than k digits. Sandy can only change 1 digit at a time, and cannot add digits to (or remove digits from) the number. Given k and an n-digit number, help Sandy determine the largest possible number she can make by changing <=k digits. Note: Treat the integers as numeric strings. Leading zeros are permitted and can't be ignored (So 0011 is not a palindrome, 0110 is a valid palindrome). A digit can be modified more than once. Input Format The first line contains two space-separated integers, (the number of digits in the number) and (the maximum number of digits that can be altered), respectively. The second line contains an n-digit string of numbers that Sandy must attempt to make palindromic. Constraints 1. 0 < n <= 10^5 2. 0 <= k <= 10^5 3. Each character i in the number is an integer where 0 <= i <= 9 Output Format Print a single line with the largest number that can be made by changing no more than k digits; if this is not possible, print -1. Sample Input 0 4 1 3943 Sample Output 0 3993 Sample Input 1 6 3 092282 Sample Output 1 992299 Sample Input 2 4 1 0011 Sample Output 2 -1 import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); String number = in.next(); // Write you solution here } }