public class EmpNoIsInteger {
public static void main(String[] args) {
String givenString = "ENAME=Myjavacafe~*ENO=9999~*";
String empNo = "*ENO";
// 01234
boolean empFlag = givenString.contains(empNo);
if (empFlag == true) {
String[] givenWords = givenString.split("~");
for (String givenWord : givenWords) {
if (givenWord.startsWith(empNo)) {
String givenEmpNo = givenWord.substring(5,
givenWord
.length());
System.out.println("Given Employee Number:" +
givenEmpNo);
boolean sFlag = isInteger(givenEmpNo);
if (sFlag == true) {
System.out
.println("Employee Number("
+givenEmpNo+") is Valid(It is Integer values)");
} else {
System.out
.println("Employee Number("
+givenEmpNo+") is Invalid(It is not Integer values).");
}
}
}
} else {
System.out.println("Employee Number is not avaliable
given String.");
}
}
public static boolean isInteger(String input) {
try {
Integer.parseInt(input);
return true;
} catch (Exception e) {
return false;
}
}
}
Output:
Scenario 1: Given Employee Number only Numbers(9999)
Given Employee Number:9999
Employee Number(9999) is Valid(It is Integer values)
Scenario 2: Given Employee Number is Alphanumeric(9999SS)
Given Employee Number:9999SS
Employee Number(9999SS) is Invalid(It is not Integer values).
Scenario 2: Given Employee Number is NULL
Given Employee Number:
Employee Number() is Invalid(It is not Integer values).
Build Your Own Test Framework
-
[image: Build Your Own Test Framework]
Learn to write better automated tests that will dramatically increase your
productivity and have fun while doing so...
2 hours ago
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.