Question

In: Computer Science

A word is said to be “abecedarian” if the letters in the word appear in alphabetical...

A word is said to be “abecedarian” if the letters in the word appear in alphabetical order. For example, the following are all six-letter English abecedarian words:

abdest, acknow, acorsy, adempt, adipsy, agnosy, befist, behint,
beknow, bijoux, biopsy, cestuy, chintz, deflux, dehors, dehort,
deinos, diluvy, dimpsy

Write a method called isAbecedarian that takes a String and returns a boolean indicating whether the word is abecedarian.

Solutions

Expert Solution

Short Summary:

  • Implemented the program to check if the string is an abecedarian.
  • As the language is not mentioned, I have given the code in java.

Source Code:

(Have created a string array in main for testing the method)

//This class checks if the String is an abecederian
public class StringOperations1 {

   //Main method
   public static void main(String[] args) {
       String[] stringArray = {"abdest","acknow", "Eclipse","acorsy", "Everyone", "adempt", "adipsy"};
       for(String str:stringArray)
       {
           boolean flag=isAbecederian(str.toLowerCase());
           if(flag)
               System.out.println("It is abecedarian");
           else
               System.out.println("It is not abecedarian");
       }

   }
   //Method to check if the String argument is an abecederian
   static boolean isAbecederian(String word){
       for(int i = 0;i<word.length()-1;i++)   
           if(word.charAt(i) > word.charAt(i+1))
               return false;
       return true;
   }

}

Code Screenshot:

Output:

**************Please do upvote to appreciate our time. Thank you!******************


Related Solutions

In C Exercise 8.1 A word is said to be “abecedarian” if the letters in the...
In C Exercise 8.1 A word is said to be “abecedarian” if the letters in the word appear in alphabetical order. For example, the following are all 6-letter English abecedarian words. abdest, acknow, acorsy, adempt, adipsy, agnosy, be?st, behint, beknow, bijoux, biopsy, cestuy, chintz, de?ux, dehors, dehort, deinos, diluvy, dimpsy a. Describe an algorithm for checking whether a given word (String) is abecedarian, assuming that the word contains only lower-case letters. Your algorithm can be iterative or recursive. b. Implement...
A machine prints a word and the number of letters in this word is a Poisson...
A machine prints a word and the number of letters in this word is a Poisson distributed random variable with parameter λ (so it could possibly have zero letters). However, each letter in the word is printed incorrectly with probability 2/3 independently of all other letters. Compute the expectation and the variance of the number of incorrect letters in the word that the machine prints.
34. Write all of the letters that are vowels in the order that they appear in...
34. Write all of the letters that are vowels in the order that they appear in the alphabet including Y. Switch the order of the second and third vowels in the list. Change the fourth and fifth vowels to Y. What does the list of the letters look like now? a. A I E O Y Y b. A I E Y Y c. A I E Y Y Y d. A I E Y 35. He answered the attorney’s...
Suppose that a “word” is any string of six letters. Repeated letters are allowed. For our...
Suppose that a “word” is any string of six letters. Repeated letters are allowed. For our purposes, vowels are the letters a, e, i, o, and u. a) How many words are there? b) How many words begin with a vowel? c) How many words begin with a vowel and end with a vowel? d) How many words have no vowels? e) How many words have exactly one vowel? A professor teaching a Discrete Math course gives a multiple choice...
Selling puts is very much like which of the following? Use letters in alphabetical order to...
Selling puts is very much like which of the following? Use letters in alphabetical order to select options A Covered calls. B Buying insurance. C Selling naked calls. D Buying stock. Buying puts is similar to which of the following? Use letters in alphabetical order to select options A Buying insurance. B Selling naked calls. C Buying stock. D Covered calls.
For the questions below, enter only the letters that are part of the answer, with no spaces or commas, in alphabetical order.
What is the size of the tax?What is the equilibrium quantity before the tax?What is the equilibrium quantity with the tax?What is the price consumers pay before taxes?What is the price consumers pay with the tax?What is the price sellers receive before taxes?What is the price sellers receive with the tax?For the questions below, enter only the letters that are part of the answer, with no spaces or commas, in alphabetical order. (Example: enter something like XYZor AZ, do not...
How are the insurance premiums determined for deposit insurance? Use letters in alphabetical order to select...
How are the insurance premiums determined for deposit insurance? Use letters in alphabetical order to select options A The insurance premium is based on the bank’s level of riskiness and then adjusted according to the level of deposits of the overall U.S. banking system. B The insurance premium is based on the bank’s level of deposits and then adjusted according to the riskiness of the overall U.S. banking system's financial situation. C The insurance premium is based on the bank’s...
If all permutations of the letters of the word "BEFORE" are arranged in the order as...
If all permutations of the letters of the word "BEFORE" are arranged in the order as in a dictionary. What is the 32 word?
Write a program that will prompt for a word with at least five letters in it...
Write a program that will prompt for a word with at least five letters in it (if not, keep asking for input). Then evaluate the word to produce a count of all the vowels in the word. Sample output appears below. Enter a word at least 5 characters long:<SPC>cat<ENTER> Enter a word at least 5 characters long:<SPC>dog<ENTER> Enter a word at least 5 characters long:<SPC>concatenate<ENTER> Letter Counts ========= a: 2 e: 2 i: 0 o: 1 u: 0
It is said that company letters of recommendations are vulnerable to legal complications. Is that true?Is...
It is said that company letters of recommendations are vulnerable to legal complications. Is that true?Is so ,why should you consult your organization's legal department before writing one?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT