Java - method to check if a String contains a given character

-2

I have a problem with this method. It seems to me that whenever I try to use it with some String, I get false for the value of a, even though the String contains those three characters. Can anyone tell me what's wrong here?

 public static boolean VerSeTemLetras (String qqString){
    boolean a;
    int tem_a;
    int tem_b;
    int tem_c;

    if (qqString.contains("a")) {
        tem_a = 1;
    } else {
        tem_a = 0;
    }
    if (qqString.contains("b")) {
        tem_b = 1;
    } else {
        tem_b = 0;
    }
    if (qqString.contains("c")) {
        tem_c = 1;
    } else {
        tem_c = 0;
    }

    a = ((tem_a + tem_b + tem_c) > 2 );

    return a;
}
    
asked by anonymous 23.08.2017 / 20:59

2 answers

1

I think this is better

public static boolean VerSeTemLetras (String qqString){
    return qqString.contains("a") && qqString.contains("b") && qqString.contains("c"); 
}
    
23.08.2017 / 21:04
1
public static boolean verSeTemAeBeC(String qqString) {
    return qqString.contains("a") && qqString.contains("b") && qqString.contains("c");
}

public static boolean verSeTemAouBouC(String qqString) {
    return qqString.contains("a") || qqString.contains("b") || qqString.contains("c");
}
    
23.08.2017 / 21:04