+ 1

Java question

write a method called remove() that takes two arguments : String and character, and returns new String that removes all accurences of the character from the input String

28th Jun 2017, 10:14 PM
Ridox
Ridox - avatar
5 odpowiedzi
+ 1
The answer package test3; public class method2009 { public static String remove(String a , char b) { for(int i = 0 ; i < a.length() ; i++){ if(a.charAt(i) !=b){ String res = ""; res = res + a.charAt(i); System.out.print(res); } } return null; } public static void main (String [] args){ remove("programming" , 'm'); } }
28th Jun 2017, 11:07 PM
Ridox
Ridox - avatar
+ 1
Just use a loop to go through each character in the string and test if its the character. If it isn't, add it to some temp string. When the loop is finished, return the temp string.
28th Jun 2017, 10:25 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
No, I'm not going to do your homework. I already tolled you how to do it anyway.
28th Jun 2017, 10:29 PM
Rrestoring faith
Rrestoring faith - avatar
0
can you write complete code i think you should use charAt() method
28th Jun 2017, 10:28 PM
Ridox
Ridox - avatar
0
it is not my homework but thank you anyway.
28th Jun 2017, 10:30 PM
Ridox
Ridox - avatar