Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 1 Write a Java program containing the static methods described in the following paragraphs. You need not include exception handling and validation in
Question 1 Write a Java program containing the static methods described in the following paragraphs. You need not include exception handling and validation in your solution. You must not use the following in your solution: Lambda expression The Stream API Methods in the Arrays class (java.util.Arrays) Methods in the Collections class (java.util.Collections) Method 1 public static void printNumbers (int startNum, int endNum, int numPerLine) { // Your code } The method will print numbers from startNum to endNum, inclusive of both ends. The method will print numPerLine numbers per line. Example 1: printNumbers (21, 29, 4) will produce the following: 21 22 23 24 25 26 27 28 29 Example 2: print Numbers (4, 12, 6) will produce the following: 4 5 6 7 8 9 10 11 12 You may assume: startNum >= 0, numPerLine > 0 startNum < endNum You must not use int [ ] or ArrayList in your solution. Method 2 public static boolean has DuplicateChars (String data) { } // Your code The method will return true if there are duplicate characters in data and false otherwise. Examples: has DuplicateChars ("abcala2") will produce true. has DuplicateChars ("morning") will produce true. hasDuplicateChars("ab$wx$y") will produce true. has DuplicateChars ("35 x 12") will produce true. (2 blank spaces) has DuplicateChars ("methods") will produce false. You may assume the letters: a, b, c ... z are in lower case. You must not use char () or ArrayList in your solution. Method 3 public static String replaceWith (String data, // Your code char chl, char ch2) { The method will return an instance of String containing all characters in data but with all occurrences of ch1 replaced by ch2. You must use recursion. Examples: replaceWith("programming", 'r' 'R'); replaceWith("java", 'a', 'A'); replaceWith("1+23+4", '+' '%'); ') Return value "pRogRamming" "jAVA". "1%2x3%4". "22-Jun-2022" replace With ("22 Jun 2022" You must not use char[] or ArrayList in your solution. Method 4 public static int countDigit (int number, int digit) { } // Your code The method will count and return the number of occurrences of digit within number. You must use recursion. Examples: count Digit (5, 0); count Digit (1, 1); countDigit (12257212, 2); countDigit (51299189, 9) You may assume: number 0 digit is 0 - 9 You must not use char[] or ArrayList in your solution. Return value 0 1 4 3 Program Structure You may include additional variables and methods as you deem fit. public class Question1 { public static void main(String[] argv) { } // Add statements to call and test the various methods. // The statements in this method will NOT be graded. } public static void print Numbers (int startNum, int endNum, int numPerLine) { // Your code } public static boolean has DuplicateChars (String data) { // Your code } public static String replaceWith (String data, // Your code } char ch1, char ch2) { public static int countDigit (int number, int digit) { // Your code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Java public class StringUtil public static void printNumb...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started