+ 1

What's wrong with this code?

public class Game { public static void main(String[] args) { String[] psh=new String [k]; String[] shekl=new String[4]; shekl[0]="đŸ”ș"; shekl[1]="đŸ””"; shekl[2]="⚫"; shekl[3]="🔮"; shekl[4]="đŸ”¶"; shekl[5]="đŸ”·"; int k= 2; int and[]=new int[k]; int msh[]=new int[k]; for(i=0;i<k;i++){ int and[i]=ran.nextInt[4]; int msh[i]=ran.nextInt[8]-4; System.out.print(shekl[and[i]]+"="+msh[i]+"/t"); } for(i=0;i<100;i++){ System.out.println(); } for(i=0;i<k;i++){ psh[i]=shekl[and[i]]; } int x=ran.nextInt(k); System.out.print(psh[x]); sum = sum + msh[i]; } }

19th Dec 2019, 6:19 PM
mahdieh
2 Answers
+ 1
The variable "k" is initialized after using it in the 1st line. Also there is no Scanner class used, so taking user inputs is not possible. Also there are syntax errors.
19th Dec 2019, 7:12 PM
Avinesh
Avinesh - avatar
0
//I don't know this game, so this is not final result but is compilable import java.util.Random; //added public class Game { public static void main(String[] args) { int k = 2, sum = 0, i; // k moved here, added sum, i Random ran = new Random(); // added String[] psh = new String[k]; String[] shekl = new String[6]; //not [4] // ... for (i = 0; i < k; i++) { //int and[i] = ran.nextInt(4); //() instead [] //int msh[i] = ran.nextInt(8) - 4; //() System.out.print(shekl[and[i]] + "=" + msh[i] + "\t"); // not "/t" } // ... System.out.print(psh[x]); i--; //added, perhaps it has not sense, but it avoid error in msh[i] where i > k sum = sum + msh[i]; } }
20th Dec 2019, 11:23 PM
zemiak