How to create a StringBuilder object that cntains equal numbers of a string
Hi
im working on a program and in the constructor i need to initialize a StringBuilder object with equal numbers of a the letters Y & N the constructor has an int argument which will specify how many of each String the StringBuilder will be initialized with. The code I have so far is:
Code :
public Questions(int aNumber)
{
super();
this.anwers = new StringBuilder(5);
}
but im now stuck as I dont know how to make itinitialize with equal numbers of eaxh string "Y" & "N"
hoe someone can help :(
How to initialize an array to contain equal numbers of a string
Hello guys
im working on a program and in the constructor i need to initialize an array with equal numbers of the Strings "Y" & "N". the constructor has an int argument which will specify how many of each String the array will be initialized with. The code I have so far is:
Code :
String answers[];
public Questions(int aNumber)
{
super();
anwers = new String[6];
}
but im now stuck as I dont know how to make itinitialize with equal numbers of eaxh string "Y" & "N"
is this even possible or am I going about this the wrong way?
I hope someone can advise me in some way as im completely stuck!
Any help is much appreciated.
Re: How to create a StringBuilder object that cntains equal numbers of a string
Please don't ask the same question multiple times.
Just fill the first half of the array with "Y" and the second half of the array with "N". You'll also want to initialize your array with two times the size of aNumber, not a static 6.
Code :
answers = new String[2*aNumber];
for (int i = 0; i < aNumber; i++)
{
answers[i] = "Y";
}
for (int i = aNumber; i < answer.length; i++)
{
answer[i] = "N";
}