Skip to main content
added 188 characters in body
Source Link

How about this?

public static String deFront(String str)
{
    String one = (str.length() > 0 && str.charAt(0) == 'a') ? "a" : "";
    String two = (str.length() > 1 && str.charAt(1) == 'b') ? "b" : "";

    return one+two+((str.length() > 2) ? str.substring(2) : "");        
}

Note that only the parentheses around the entire ternary operation in the return are actually necessary, the others are for readability, as per @abuzittingillifirca's suggestion.

How about this?

public static String deFront(String str)
{
    String one = str.length() > 0 && str.charAt(0) == 'a' ? "a" : "";
    String two = str.length() > 1 && str.charAt(1) == 'b' ? "b" : "";

    return one+two+(str.length() > 2 ? str.substring(2) : "");        
}

How about this?

public static String deFront(String str)
{
    String one = (str.length() > 0 && str.charAt(0) == 'a') ? "a" : "";
    String two = (str.length() > 1 && str.charAt(1) == 'b') ? "b" : "";

    return one+two+((str.length() > 2) ? str.substring(2) : "");        
}

Note that only the parentheses around the entire ternary operation in the return are actually necessary, the others are for readability, as per @abuzittingillifirca's suggestion.

deleted 30 characters in body
Source Link

How about this?

public static String deFront(String str)
{
    String uno, dos;        

    unoone = str.length() > 0 && str.substringcharAt(0,1).equals("a") == 'a' ? "a" : "";
    dosString two = str.length() > 1 && str.substringcharAt(1,2).equals("b") == 'b' ? "b" : "";

    return uno+dos+one+two+(str.length() > 2 ? str.substring(2) : "");        
}

How about this?

public static String deFront(String str)
{
    String uno, dos;        

    uno = str.length() > 0 && str.substring(0,1).equals("a") ? "a" : "";
    dos = str.length() > 1 && str.substring(1,2).equals("b") ? "b" : "";

    return uno+dos+(str.length() > 2 ? str.substring(2) : "");        
}

How about this?

public static String deFront(String str)
{
    String one = str.length() > 0 && str.charAt(0) == 'a' ? "a" : "";
    String two = str.length() > 1 && str.charAt(1) == 'b' ? "b" : "";

    return one+two+(str.length() > 2 ? str.substring(2) : "");        
}
added 65 characters in body
Source Link

How about this?

public static String deFront(String str)
{
    String uno, dos;         

    
 uno = str.length() > uno0 =&& str.substring(0,1).equals("a") ? "a" : "";
    dos = str.length() > 1 && str.substring(1,2).equals("b") ? "b" : ""; 

    
 return uno+dos+(str.length() > 2 return? uno+dos+strstr.substring(2) : "");        
}

How about this?

public String deFront(String str)
{
    String uno, dos;        
    
     uno = str.substring(0,1).equals("a") ? "a" : "";
    dos = str.substring(1,2).equals("b") ? "b" : "";
    
     return uno+dos+str.substring(2);        
}

How about this?

public static String deFront(String str)
{
    String uno, dos;         

    uno = str.length() > 0 && str.substring(0,1).equals("a") ? "a" : "";
    dos = str.length() > 1 && str.substring(1,2).equals("b") ? "b" : ""; 

    return uno+dos+(str.length() > 2 ? str.substring(2) : "");        
}
Source Link
Loading