java - Can't replace a letter in a string -
i have asked couple of questions loop:
string[] book = new string [isbn_num]; booknum.replaceall("-",""); if (booknum.length()!=isbn_num) throw new isbnexception ("isbn "+ booknum + " must 10 characters"); (int i=0;i<booknum.length();i++) { if (character.isdigit(booknum.charat(i))) book[j]=booknum.charat(i); //this problem right here j++; if (book[9].isnotdigit()|| book[9]!="x" || book[9]!="x") throw new isbnexception ("isbn " + booknum + " must contain digits" + "or 'x' in last position"); }
which not compile. answer had other question asked told me line error occurs wrong in booknum.charat(i) (immutable) string, , can't values book array way. need on assignment check isbn number (booknum) see numbers, except last digit can 'x' (valid isbn). best way it? if so, hell doing wrong? if not, method better 1 use?
book
of type string[]
(array of strings), booknum.charat(i)
returns char
. can't assign string
char
.
do book[j] = string.valueof(booknum.charat(i))
instead.
also might want change first error:
throw new isbnexception ("isbn "+ booknum + " must " + isbn_num + " characters");
Comments
Post a Comment