- Code: Select all
public String toString() {
if(counter == 0) //only true for an empty set
return "---";
else
for(i = 0; i < 11; i++)
if(set[i])
return i + " ";
}
Thanks XKCDers!
Moderators: phlip, Moderators General, Prelates
public String toString() {
if(counter == 0) //only true for an empty set
return "---";
else
for(i = 0; i < 11; i++)
if(set[i])
return i + " ";
}phlip wrote:On the other hand, the "11" value should be a class variable, specifically a "static final int SIZE = 11;". So that it's much easier to see when reading the code what the 11 represents, and it's also much easier to come in later and change the size of the set.
public String toString() {
String print = " ";
if(counter == 0) //only true for an empty set
return "---";
else
for(int i = 0; i < size; i++)
if(set[i])
print = print + i + " ";
return print;
} public String toString() {
String print = " ";
if(counter == 0) //only true for an empty set
return "---";
for(int i = 0; i < set.length; i++){
if(set[i]){
print = print + i + " ";
}
}
return print;
}
Users browsing this forum: No registered users and 9 guests