When do test of scramble()
method it actually returns something like this:
public class Scramble_game {
public static void main(String[] args)
{
System.out.println("START");
Word name = new Word("iskander");
System.out.println(name.getWord() + " " + name.getScrambleWord());
}
}
my output is always like this:
START
[C@57f530d8 [C@2259e205
public class Word
{
char[] word;
char[] scrambleWord;
boolean[] letters;
boolean correct;
public Word(String wordName)
{
this.word = wordName.toCharArray();
this.letters = new boolean[wordName.length()];
this.correct = false;
this.scrambleWord = this.scramble();
}
public char[] getScrambleWord(){return this.scrambleWord;}
public char[] getWord(){return this.word;}
public int getIndex()
{
Random rnd = new Random();
int i = rnd.nextInt(this.word.length);
if(this.letters[i] == true)
{
return getIndex();
}
this.letters[i] = true;
return i;
}
public char[] scramble()
{
char[] temp = new char[this.word.length];
for(int i = 0; i < this.word.length; i++)
{
char tempChar = word[this.getIndex()];
temp[i] = tempChar;
}
return temp;
}
}
As I understood this strange words are the addresses of objects? I might be wrong, can you explain me what are these strange letters and where is my code problem.