Java: Check if each letter of a given word is less than the one before it
Java Basic: Exercise-248 with Solution
From Wikipedia, An abecedarium (or abecedary) is an inscription consisting of the letters of an alphabet, almost always listed in order. Typically, abecedaria (or abecedaries) are practice exercises.
Write a Java program to check if each letter of a given word (Abecadrian word) is less than the one before it.
Sample Solution:
Java Code:
import java.util.*;
public class solution {
public static boolean is_abecedarian_word(String word) {
int index = word.length() - 1;
for (int i = 0; i < index; i++) {
if (word.charAt(i) <= word.charAt(i + 1)) {
}
else {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Input a word: ");
String word1 = scanner.nextLine();
System.out.println("Is Abecadrian word? "+is_abecedarian_word(word1));
}
}
Sample Output:
Input a word: ABCD Is Abecadrian word? true
Flowchart:

Java Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Java program which accepts three integers and check whether sum of the first two given integers is greater than third one. Three integers are in the interval [-231, 231 ]
Next: Write a Java program to count the number of set bits in a 32-bit integer.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join