Topics Index

Is given word in descending order

If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to check whether the characters in the given word are in descending order or not.

Input (String) Output (Boolean)
dcba true
zyxw true
zwyx false
zonked true
zeitgeist false
yule true
troubles false

class IsDescendingWord
    public static void main(String s[])
        String inputWord = "zonked";
        System.out.println("Is " + inputWord + " in descending order : " + isInDescendingOrder(inputWord));


    public static boolean isInDescendingOrder(String inputWord) {

Topic: Conclusion Of Strings In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

here logic is check each character to all its previous character means here we checking its ascii values  present character ascci value  must be less than all its prevous characters ascii values in string ,if all charcter are satisfies these condition means it is in descending order
here c is value is less than d ok
     b is less than  d,c
     a is less than  d,c,b
     means its is in desending ordeer return true
program logic:
in this program we want nested loop
1.first created a boolean variable value assigned is true

2.  start outer for loop i=(index) 1 to inputWord.length()
      innerloop from for j=0 to i
  condition is inputword(j)>inputword(i) return false;(if any character is greater than its previous character simply return false)
3.if loops are completed successfully means string is desending order then return true

Posted by Goutham Singarapu    2015-03-10 15:14:10

here every char should be greater than its next char (cba)
start for loop i =0 and till it reaches the size-1 and tak one boolean
variable res if the charAt(i)>=charAt(i+1) if it is true than res=true else
return false
after coming out of the loop return result

Posted by Uday Kumar    2015-03-10 15:27:17

This dose is now closed and the winners are Goutham Singarapu,  for 'First Correct Comment', Goutham Singarapu,  for 'Second Correct Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-03-11 02:03:18

© meritcampus 2019

All Rights Reserved.

Open In App