Java > Warmup-1 > delDel (CodingBat Solution)

Problem:

Given a string, if the string "del" appears starting at index 1, return a string where that "del" has been deleted. Otherwise, return the string unchanged.

delDel("adelbc") → "abc"
delDel("adelHello") → "aHello"
delDel("adedbc") → "adedbc"


Solution:

public String delDel(String str) {
  if (str.startsWith("del", 1))
    return str.charAt(0) + str.substring(4, str.length());
  else
    return str;
}


2 comments :

  1. function delDel(str){
    let a = str.substr(1,3);
    if (a == 'del'){
    return str.replace('del', '');
    } else return str;


    }

    ReplyDelete
  2. public String delDel(String str) {
    return (str.startsWith("del",1))?str.replace("del", ""):str;
    }

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact