A word displayed in descending order

sravan953 1 Tallied Votes 342 Views Share

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));
            }
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.