I am writing a program that takes a
string of numbers, and runs it though the following method to make sure that it has exactly seven digits and I know this part of the method works. It makes sure there aren't 1's or 0's in the number, and I know this part of the method works. Lastly, I am trying to make it make sure that the only things in the number are infact numbers, if they aren't I want it to error. I cannnot for the life of me see why it always errors on that, even if I put in a completely valid string. I know the other parts work perfectly, however when I put in a normal
test string it errors because of the part that checks to make sure there aren't other anything other than digits in it.
public String test () {
String error1="Error type1";
String error3="Error type3";
int length=numbers.length();
if(length<7 || length >7)
return(error1);
for(int i=0; i<length; i++){
char number=numbers.charAt(i);
if(number =='0' || number =='1')
return(error3);
if(number!='2' || number!='3' || number!='4' || number!='5' || number!='6' || number!='7' || number!='8' || number!='9')
return(error1);
}
return(numbers);
}