Start New Discussion within our Software Development Community

This code snippet displays any word that the user enters in descending order, each time, removing the last charcter.

So, sravan953 in descending order would be:

sravan953
sravan95
sravan9
sravan
srava
srav
sra
sr
s

import java.io.*;
class word_descend
{
static void descend()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the word or sentece which you want to display in descending order:\n");
        String s=br.readLine();
        int l=s.length();
        for(int j=l;j>=0;j--)
            {
                System.out.println(s.substring(0,j));
            }
        }
    }
The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.