0

Error in random function

This program is cant be compiled (some error in Math.random) public class Generator { public static void main (String[] args) { String[] listOne={"Кровавые","Чудовищные","Устрашающие", "Надвигающиеся","Технологические", "Космические","Новые","Полезные"}; String[] listTwo={"Зубы","Когти","Лезвия","Взгляды", "Воспоминания","Следы","Слезы","Приключения","Навыки"}; String[] listThree={"Потомков","Предков","Динороботов", "Злодеев","Карликов","Крыс","Монстры"}; String[] listFour={"Часть","Эпизод","Книга"}; String[] listFive={"1","2","3","6","12","7","4","19","8","0","9","10"}; String[] listSix={"Смертльная","Черная","Белая", "Последняя","Первая"}; String[] listSeven={"Книга","Песнь","Мысль", "Жизнь","Надежда"}; int One=listOne.length; int Two=listTwo.length; int Three=listThree.length; int Four=listFour.length; int Five=listFive.length; int Six=listSix.length; int Seven=listSeven.length; int rand1 = (int) (Math.random() * One); int rand2 = (int) (Math.random() * Two); int rand3 = (int) (Math.random() * Three); int rand4 = (int) (Math.random() * Four); int rand5 = (int) (Math.random() * Five); int rand6 = (int) (Math.random() * Six); int rand7 = (int) (Math.random() * Seven); String phrase=listOne[rand1]+" "+listTwo[rand2]+" "+listThree[rand3]+ " "+listFour[rand4]+" "+listFive[rand5]+": "+listSix[rand6]+ " "+listSeven[rand7]; System.out.println("Coming soon: "+phrase); } }

11th Aug 2016, 1:25 AM
Artkham Z
Artkham Z - avatar
4 Respuestas
+ 3
It's not the random. It's actually your strings. Youre using a character that is not compatible with the language by default. Keep in mind, the strings get stored as UTF-16 I believe? So if you use a symbol that doesn't have a conversion, program can't compile it. Unfortunately, I don't know if it's just one or all, since I don't know that language and whether it's supported. Yours might be UTF-8? which requires some additional coding. You'll have to google how to do that, since it's not my area of expertise.
11th Aug 2016, 4:00 AM
James
James - avatar
0
oh ok i think i see it, ok so if you go down to your math.random part, have another ( infront. like this: int ranf1 = (int) ((Math.random() *One); and do that for every one that you have. hope that helped if not, sorry cause i couldnt read your top code.
11th Aug 2016, 1:55 AM
Aquarius
Aquarius - avatar
0
wait james, correct me if im wrong but, doesnt he have to have another opening parenthesis. like i shown in my example? Because he does have a closing parenthesis second to the end.
11th Aug 2016, 12:18 PM
Aquarius
Aquarius - avatar
0
no. he's got the correct amount of parenthesis. try it yourself, just copy and paste his code, then just replace Strings with English versions. works just fine You've got an extra parenthesis. (int) has 1 at beginning and end. All set. beginning> (Math.random(***parameter beginning and end parenthesis) * ONE) < end parenthesis
11th Aug 2016, 12:25 PM
James
James - avatar