+ 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]; } }
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.
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];
}
}