Java- Array/String mashup error? -
i have slight problem @ moment java code can't pick random string array have. segment of code here:
private static string core; { string[] insults = new string[15]; insults[0] = "so's mum."; insults[1] = "i hate too."; insults[2] = "freak!"; insults[3] = "your balls peas."; insults[4] = "you're ugly, birth certificate apology letter condom factory."; insults[5] = "ooh, take me burn unit."; insults[6] = "that insult dick- pathetic."; insults[7] = "your mum looks dog. brought not lie."; insults[8] = "can away? it's killing face..."; insults[9] = "if had house every insult gave me, you'd still living on streets!"; insults[10] = "shut up, you'll never man mother is."; insults[11] = "shut up, you'll never man mother is."; insults[12] = "oh god... face squashed in vice @ birth?"; insults[13] = "i know are, i?"; insults[14] = "oh, okay then..."; double count = 0; }; public static void output(string output) { string insult1 = tpicore.core[(new random()).nextint(insults.length)]; }
you can see here i'm trying do. pick random insult list above. if try , run code, throws error @ tpicore.core[(new random()).nextint(insults.length)];
, "saying type of expression must array type resolved string". then, when change type array, throws kinds of errors along core class. don't know i'm doing wrong. can help?
if must use static variables, here how it.
public class tpicore { private static string[] insults = new string[15]; static { insults[0] = "xxx"; insults[1] = "yyy"; insults[2] = "zzz"; // etc... } public static void main(string[] args) { string insult1 = tpicore.insults[new random().nextint(insults.length)]; system.out.println(insult1); } }
however suggest more this. luck.
public class tpicore { private string[] insults = new string[15]; public tpicore() { insults[0] = "xxx"; insults[1] = "yyy"; insults[2] = "zzz"; // etc... } private string randominsult() { return insults[new random().nextint(insults.length)]; } public static void main(string[] args) { tpicore core = new tpicore(); string insult1 = core.randominsult(); system.out.println(insult1); } }
Comments
Post a Comment