ReverseSentence

ReverseSentence - s = s.substring(space+1); space =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class ReverseSentence { public static void main(String[] args) { String s; String reversed = ""; System.out.println("Please enter a sentence:"); s = IO.readString(); s=s+" "; int space = s.indexOf(" "); while(space != -1){ String word = s.substring(0,space); reversed = word + " " + reversed;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s = s.substring(space+1); space = s.indexOf(" "); } reversed = reversed.substring(0,reversed.length() -1).concat("."); String first = reversed.substring(0,1); reversed = first.toUpperCase().concat(reversed.substring(1)); IO.outputStringAnswer(reversed); } }...
View Full Document

Ask a homework question - tutors are online