Are the letters consecutive? Write a Boolean function isConsecutive that looks a
ID: 3601522 • Letter: A
Question
Are the letters consecutive? Write a Boolean function isConsecutive that looks at a string and then determine if the letters are occurring consecutively in the string. The function also determine the number of characters in the string, and the number of letters. Restrictions: The function should use the internal function isletter. The input string could be any length. Hint: This problem can use the break statement. For example [consecutiveLetters, numberCharacters, numberLetters] isConsecutive (string) >> string='123', string = = 123 consecutiveLetters - logical numberCha racters = numbe rLet ters >> string="Josh2a. [consecutiveLetters, numberCharacters, numberLet ters] 1sConsecutive ( string) = string "Josh2a consecutiveetters logical numberCharacters - numberLetters = >> string='3rd .. [consecutiveLetters, numberCharacters, numberLetters] isConsecutive(string) = string consecutiveetters = logical numberCharacters - 4Explanation / Answer
public class findConsSubString{
public static boolean find(String s){
int ptr1;
int ptr2;
int i = 1;
int count;
if(s.length() < 2)
return false;
while(i <= s.length() / 2){
ptr1 = 0;
ptr2 = i;
count = 0;
while(ptr2 < s.length()){
if(s.charAt(ptr1) == s.charAt(ptr2))
count++;
else
count = 0;
if(count == i){
return true;
}
ptr1++;
ptr2++;
}
i++;
}
return false;
}
public static void main(String[] args){
boolean found = find(args[0]);
System.out.println("Found Cons SubStrings:" + found);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.