In: Computer Science
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.
Short Summary:
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!******************