on 05-08-2013 4:35 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.