+ 1

why isnt it working?

import java.util.*; public class Main { public static void main(String[] args) { String a = "hello and bye"; if (a.contains ("bye")){ a.replace ("bye" , "c Ya later"); } System.out.println(a); } }

22nd Jul 2020, 2:56 PM
Yahel
Yahel - avatar
3 Respuestas
+ 2
You need to store a.replace in any Variable so that you can print it. String a is still "hello and bye". a.replace don't changes value of a it just creates a new String.Which needed to be strored in some variable.So that it can be printed See this Code : https://code.sololearn.com/c7AS9Wl16eJk/?ref=app
22nd Jul 2020, 3:05 PM
Akash
Akash - avatar
+ 2
yahel And Please Don't write your Code in question next time.It is hard to read and understand in that way.Please click on edit your question and then on plus icon and then Click on Insert Code to insert your Code.Then Everyone can understand your question and can answer you.
22nd Jul 2020, 3:07 PM
Akash
Akash - avatar
+ 1
Akash thanks!
22nd Jul 2020, 3:06 PM
Yahel
Yahel - avatar