1

Every time I try doing the trim method and the lowercase method it doesn't show the way I want it.

sentence.trim();
sentence.toLowerCase();
System.out.println("\"" + sentence + "\"" + " ---> ");

For example, if I input " Hello World! ", it will print out " Hello World! " and not use any of the methods.

3 Answers3

10

You need to store the value returned:

sentence = sentence.trim().toLowerCase();
Milo
  • 3,197
  • 9
  • 27
  • 40
Amer Qarabsa
  • 6,108
  • 3
  • 19
  • 38
3

You need to do

sentence = sentence.trim();
sentence = sentence.toLowerCase();
Hypnic Jerk
  • 1,167
  • 2
  • 14
  • 30
1

They don't trim or lowercase "in-place"

You could just put it in the print statement, though

System.out.println("\"" + sentence.trim().toLowerCase() + "\"" + " ---> ");
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216