Exercise 7.6 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, behint, beknow,
bijoux, biopsy, cestuy, chintz, dehors, dehort, deinos, diluvy,
dimpsy
a. Describe an algorithm for checking whether a give word (String) is abecedarian,
assuming that the word contains only lower-case letters. Your algorithm can be
iterative or recursive.
b. Implement your algorithm in a method called isAbecedarian.in alphabetical order. For example, the following are all 6-letter English abecedarian
words.
abdest, acknow, acorsy, adempt, adipsy, agnosy, behint, beknow,
bijoux, biopsy, cestuy, chintz, dehors, dehort, deinos, diluvy,
dimpsy
a. Describe an algorithm for checking whether a give word (String) is abecedarian,
assuming that the word contains only lower-case letters. Your algorithm can be
iterative or recursive.
Here is what I got so far:
Code:
public class Main {
public static void main(String[] args) {
String word1 = "abcdefg";
int index = 0;
char x = word1.charAt(index);
char y = word1.charAt(index++);
int z = x.compareTo(y);
if (z < 0) {
System.out.println ("name1 comes before name2.");
} else if (z > 0) {
System.out.println ("name2 comes before name1.");
}
}
}

