Saturday, December 7, 2013

Java Program to check whether the words in a string are in ascending order or not.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class AscendingOrder {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        System.out.println(" Enter the String ");
        Boolean flag = true;
        String str = reader.readLine();
        for (int index = 0; index <= str.length() - 2; index++) {
            int check = (int) str.charAt(index) - (int) str.charAt(index + 1);
            if (check > 0)
                flag = false;

        }
        if (flag) {
            System.out.println(" Ascending Order");

        } else {
            System.out.println(" Not in Ascending Order");

        }

    }

}

No comments:

Post a Comment