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,365
  • 9
  • 30
  • 44
Amer Qarabsa
  • 6,412
  • 3
  • 20
  • 43
3

You need to do

sentence = sentence.trim();
sentence = sentence.toLowerCase();
Hypnic Jerk
  • 1,192
  • 3
  • 14
  • 32
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
  • 179,855
  • 19
  • 132
  • 245