cancel
Showing results for 
Search instead for 
Did you mean: 

Condition does not working...

former_member472138
Active Contributor
0 Kudos

Hi,

This below code does not working for me.

from the input variable a, am taking last digit and checking if any of the digit is equal then sending USA or GB.

char d="";

int m=a.length();

d=a.substring(m-1);

   if(d=="0"||d=="1"||d=="2"||d=='3'||d=="4"||d=="5"||d=="6"||d=="7"||d=="8"||d=="9"||d=="{"||d=="A"||d=="B"||d=="C"||d=="D"||d=="E"||d=="F"||d=="G"||d=="H"||d=="I")

        return "USA";

else if(d=="&"||d=="^"||d=="K"||d=="L"||d=="M"||d=="N"||d=="O"||d=="P"||d=="Q"||d=="R")

     return "GB";

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

For character operations, you should use quotation mark instead of double quotes. See code below:

char d;

int m=a.length()-1;

d=a.charAt(m);

if(d=='0'||d=='1'||d=='2'||d=='3'||d=='4'||d=='5'||d=='6'||d=='7'||d=='8'||d=='9'||d=='{'||d=='A'||d=='B'||d=='C'||d=='D'||d=='E'||d=='F'||d=='G'||d=='H'||d=='I')

return "USA";

else if(d=='&'||d=='^'||d=='K'||d=='L'||d=='M'||d=='N'||d=='O'||d=='P'||d=='Q'||d=='R')

return "GB";

Hope this helps,

Mark

former_member472138
Active Contributor
0 Kudos

says Missing return statement.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

I just copied the code you pasted above and placed character operations. Please add this at the end of the code

else

return "not found";

Regards,

Mark

Answers (1)

Answers (1)

former_member201264
Active Contributor
0 Kudos

Hi,

Write as below:

String d = null;

int m = a.length();

d = a.substring(m-1, m);

-------------------------

   if d.equals ("0" or "1"||d=="2"||d=='3'||d=="4"||d=="5"||d=="6"||d=="7"||d=="8"||d=="9"||d=="{"||d=="A"||d=="B"||d=="C"||d=="D"||d=="E"||d=="F"||d=="G"||d=="H"||d=="I")

        return "USA";

else if(d=="&"||d=="^"||d=="K"||d=="L"||d=="M"||d=="N"||d=="O"||d=="P"||d=="Q"||d=="R")

     return "GB"

--------------------------------

Use as below:

class ConditionalDemo1 {

    public static void main(String[] args){
        int value1 = 1;
        int value2 = 2;
        if((value1 == 1) && (value2 == 2))
            System.out.println("value1 is 1 AND value2 is 2");
        if((value1 == 1) || (value2 == 1))
            System.out.println("value1 is 1 OR value2 is 1");
    }
}

Regards,

Sreeni.

former_member472138
Active Contributor
0 Kudos

facing typecasting issue.