954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can anyone advise me how to output the last character of a word - java

Program reads in a word and outputs the last character then a "," then the last 2 characters of the word

tmcculloch
Newbie Poster
2 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

what program reads and send some outPut

mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

This is what i hope to output
input/output
Enter a word: dog
g, go, god

tmcculloch
Newbie Poster
2 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

Normally i don't do homework assignments, but hey , i'm in a good mood..
I haven't tested this code, but i think it should do the trick.

String input = "dog";
     String output = "";
     for (int i = (input.length() - 1); i >= 0; i--)
      output += (input.charAt(i));
    for(int i = output.length(); i > 0 ; i--)

        System.out.println(output.substring(output.length()-i,output.length()));
    }
steelshark
Junior Poster in Training
57 posts since Sep 2010
Reputation Points: 10
Solved Threads: 5
 

Nope, doesn't work - and as a general rule we don't just hand students completed solutions to their homework problems.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

well, it needs a litle finetuning i agree on that ;)
but it should get him started on figuring it out on his own..

steelshark
Junior Poster in Training
57 posts since Sep 2010
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: