954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

A word displayed in descending order

By Sravan R on Jul 18th, 2009 6:21 pm

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));
            }
        }
    }

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You