0

i need to pass a String to a method, but it doesn't work...

public static void main(String[] args) {


    System.out.println("Enter a String:");
    String abd = Input.readString();

    long number = number(String abd);
    System.out.println(number);

}
public static long number(String abd){
    long num= 0;

    if(abd == "AAA"){
        num = 100L;
    }
    if(abd == "BB"){
        ean2 = 20L;
    }

    return ean2;

it prints 0 for the number...and i dont know why! i need to do this with a String...i know it would work with char...is there some way to make this work with String?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Change `long number = number(String abd);` to `long number = number( abd);`. While passing arguments, you don't have to mention the type. And then look at the question used to mark this as a duplicate – TheLostMind Nov 08 '15 at 14:06
  • thank you for your fast response! but unfortunatly that doesn't change the problem! –  Nov 08 '15 at 14:08
  • Did you change `==` to `.equals()`?. Also, you probably need an `else if` instead of `if` in the `"abd.equals("BB")` check – TheLostMind Nov 08 '15 at 14:08
  • Use `.euals()`: http://stackoverflow.com/questions/767372/java-string-equals-versus. – Mateusz Grzejek Nov 08 '15 at 14:08

0 Answers0