Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help with this method to find below int countNumbers(); /** * Returns a string that consists of all and only the characters in positions

please help with this

method to find below

int countNumbers(); /**  * Returns a string that consists of all and only the characters in positions n, 2n, 3n, and  * so on in the current string, starting either from the beginning or from the end of the  * string. The characters in the resulting string should be in the same order and with the  * same case as in the current string.  *  * If the current string is empty or has less than n characters, the method should return an  * empty string.  *  * Examples:  * - For n=2 and a string of one character, the method would return an empty string.  * - For n=2 and startFromEnd=false, the method would return the 2nd, 4th, 6th, and so on  * characters in the string.  * - For n=3 and startFromEnd=true, the method would return the 3rd from the last character  * in the string, 6th from the last character in the string, and so on (in the order in  * which they appear in the string).  *  * Values n and startFromEnd are passed as parameters. The starting character, whether it is  * the first one or the last one in the string, is considered to be in Position 1.  *  * @param n Determines the positions of the characters to be returned  * @param startFromEnd Determines whether to start counting from the end or from the  * beginning when identifying the characters in position n, 2n, 3n, and so  * on. Please note that the characters are always returned in the order in  * which they appear in the string.  * @return String made of characters at positions n, 2n, and so on in the current string  * @throws IllegalArgumentException If "n" less than or equal to zero  * @throws NullPointerException If the current string is null and "n" is greater than zero  *  */

public int countNumbers() { String[] charArray = currString.split(" "); int counter = 0; if (null == currString) throw new NullPointerException(); else if (currString.isEmpty()) return 0; else { for (String c : charArray) { try { Integer.parseInt(c); } catch (NumberFormatException exception) { counter++; } } } return charArray.length - counter; } 

this code is not giving me what I need please help

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

Question What are the requirements for a safe harbor 401(k) plan?30

Answered: 1 week ago