hi friends
can any one help me in following program
my requirements are
1]to check if any
String which we enter has any white space or not
2] to check our String has any number in it or not
i have achieved first task by
private boolean whitespace_check(String s) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt( (int) i) == ' ') {
return true;
}
}
return false;
}
but i am not able to achieve second task
code for second task is private boolean number_check(String s) {
for (int i = 0; i < s.length(); i++)
{
for (int j = 0; j <= 9; j++) {
if (s.charAt(i) == (char) j) {
return true;
}
}
}
return false;
}
my whole code is package New_programs;
public class Stringchecking {
private boolean whitespace_check(String s) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt( (int) i) == ' ') {
return true;
}
}
return false;
}
//my problem area private boolean number_check(String s) {
for (int i = 0; i < s.length(); i++)
{
for (int j = 0; j <= 9; j++) {
if (s.charAt(i) == (char) j) {
return true;
}
}
}
return false;
}
public static void main(String[] ar) {
String s1 = "ganeshpol007";
Stringchecking sc = new Stringchecking();
if (sc.whitespace_check(s1)) {
System.out.println("it contains white space");
}
else {
System.out.println("it does not contains white space");
}
if (sc.number_check(s1)) {
System.out.println("it contains numbers");
}
else {
System.out.println("it does not contain number");
}
}
}