Ég er að reyna að tjasla saman kóða sem, ideally, ætti að keyra main fall sem býr til 10 random lykilorð sett saman úr 4 atkvæðum úr stóru fylki og 3 tölustöfum. Ég er greinilega orðinn ryðgaðri en ég hélt, því þetta gengur hálf brösulega hjá mér. Getur einhver bent mér á hvað gæti verið orsök NullPointerException í System.out.println línunni hjá mér?
import java.util.Random; class Lyklasmidur { private static Random rand; private static String[] atkv; public Lyklasmidur() { String[] atkv = new String[126]; atkv[0] = new String("ska"); atkv[1] = new String("ba"); atkv[2] = new String("be"); atkv[3] = new String("bi"); atkv[4] = new String("bo"); atkv[6] = new String("by"); atkv[7] = new String("ca"); atkv[8] = new String("ce"); atkv[9] = new String("ci"); atkv[10] = new String("co"); atkv[11] = new String("cu"); atkv[12] = new String("cy"); atkv[13] = new String("da"); atkv[14] = new String("de"); atkv[15] = new String("di"); atkv[16] = new String("do"); atkv[17] = new String("du"); atkv[18] = new String("dy"); atkv[13] = new String("da"); atkv[14] = new String("de"); atkv[15] = new String("di"); atkv[16] = new String("do"); atkv[17] = new String("du"); atkv[18] = new String("dy"); atkv[19] = new String("fa"); atkv[20] = new String("fe"); atkv[21] = new String("fi"); atkv[22] = new String("fo"); atkv[23] = new String("fu"); atkv[24] = new String("fy"); atkv[25] = new String("ga"); atkv[26] = new String("ge"); atkv[27] = new String("gi"); atkv[28] = new String("go"); atkv[29] = new String("gu"); atkv[30] = new String("gy"); atkv[31] = new String("ha"); atkv[32] = new String("he"); atkv[33] = new String("hi"); atkv[34] = new String("ho"); atkv[35] = new String("hu"); atkv[36] = new String("hy"); atkv[37] = new String("ja"); atkv[38] = new String("je"); atkv[39] = new String("ji"); atkv[40] = new String("jo"); atkv[41] = new String("ju"); atkv[42] = new String("jy"); atkv[43] = new String("ka"); atkv[44] = new String("ke"); atkv[45] = new String("ki"); atkv[46] = new String("ko"); atkv[47] = new String("ku"); atkv[48] = new String("ky"); atkv[49] = new String("la"); atkv[50] = new String("le"); atkv[51] = new String("li"); atkv[52] = new String("lo"); atkv[53] = new String("lu"); atkv[54] = new String("ly"); atkv[55] = new String("ma"); atkv[56] = new String("me"); atkv[57] = new String("mi"); atkv[58] = new String("mo"); atkv[59] = new String("mu"); atkv[60] = new String("my"); atkv[61] = new String("na"); atkv[62] = new String("ne"); atkv[63] = new String("ni"); atkv[64] = new String("no"); atkv[65] = new String("nu"); atkv[66] = new String("ny"); atkv[67] = new String("pa"); atkv[68] = new String("pe"); atkv[69] = new String("pi"); atkv[70] = new String("po"); atkv[71] = new String("pu"); atkv[72] = new String("py"); atkv[73] = new String("qa"); atkv[74] = new String("qe"); atkv[75] = new String("qi"); atkv[76] = new String("qo"); atkv[77] = new String("qu"); atkv[78] = new String("qy"); atkv[79] = new String("ra"); atkv[80] = new String("re"); atkv[81] = new String("ri"); atkv[82] = new String("ro"); atkv[83] = new String("ru"); atkv[84] = new String("ry"); atkv[85] = new String("sa"); atkv[86] = new String("se"); atkv[87] = new String("si"); atkv[88] = new String("so"); atkv[89] = new String("su"); atkv[90] = new String("sy"); atkv[91] = new String("ta"); atkv[92] = new String("te"); atkv[93] = new String("ti"); atkv[94] = new String("to"); atkv[95] = new String("tu"); atkv[96] = new String("ty"); atkv[97] = new String("va"); atkv[98] = new String("ve"); atkv[99] = new String("vi"); atkv[100] = new String("vo"); atkv[101] = new String("vu"); atkv[102] = new String("vy"); atkv[103] = new String("wa"); atkv[104] = new String("we"); atkv[105] = new String("wi"); atkv[106] = new String("wo"); atkv[107] = new String("wu"); atkv[108] = new String("wy"); atkv[109] = new String("xa"); atkv[110] = new String("xe"); atkv[111] = new String("xi"); atkv[112] = new String("xo"); atkv[113] = new String("xu"); atkv[114] = new String("xy"); atkv[115] = new String("za"); atkv[116] = new String("ze"); atkv[117] = new String("zi"); atkv[118] = new String("zo"); atkv[119] = new String("zu"); atkv[120] = new String("zy"); atkv[121] = new String("ske"); atkv[122] = new String("ski"); atkv[123] = new String("sko"); atkv[124] = new String("sku"); atkv[125] = new String("sky"); rand = new Random(); } public static void main( String[] args ) { for( int i=1; i<11; i++ ) { System.out.println( "" + atkv[rand.nextInt( 125 )] + atkv[rand.nextInt( 125 )] + atkv[rand.nextInt( 125 )] + atkv[rand.nextInt( 125 )] + rand.nextInt( 10 ) + rand.nextInt( 10 ) + rand.nextInt( 10 ) ); } } }
Peace through love, understanding and superior firepower.