Constructor using multiple arrays in java -
having trouble creating constructor takes multiple 1 dimensional arrays of string
s:
class relation { string[] seta, setb, setc; relation (string[] seta, string[] setb, string[] setc) { this.seta = seta; this.setb = setb; this.setc = setc; } } public class matrix { public static void main(string[] args) { relation relation1 = new relation({"1","2","3","4","5"}, {"1","2","3","4"}, {"2","3","4","5"}); relation relation2 = new relation({"a","b","c","d"}, {"a","b","c","d","b","c"}, {"a","b","c","d","c","b"}); } }
i keep getting multiple errors - syntax error on token(s), misplaced construct(s) - type mismatch: cannot convert string[] relation - syntax error on token "}", delete token - syntax error on token ")", } expected
i need able use each array separately withing relation class.
you can't use array literals way in java - have explicitly initialize them. e.g.:
relation relation1 = new relation(new string[]{"1","2","3","4","5"}, new string[]{"1","2","3","4"}, new string[]{"2","3","4","5"});
Comments
Post a Comment