I learned some java in school just 4 weeks ago, so i do not know much things ... so requires your help!!

String[] alphabetArray = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

The code above is the array i created with all 26 of the alphabets inside.

How do i create a method or write a code to generate a list with 10 letters.

It's like a scrabble game except it goes like this:

Player 1 goes first before player 2 and got 10 random generated letters. He can create any word as long as he use the words he possesses. And he entered. The score will be given for the word, however, for the second round, the words not used will appear before him again but the words he used up (e.g. 5 words), so 5 new random letters will be generated.

So how do i go from here?

My brother taught me a code, but i do not want to copy that and anyway i do not understand what the codes mean and how it functions :

public class TestClass {
	static char[] lettersArray = new char[26];
	static int count = 0;

	public static void addChar(char[] findyourletters, char c, int times) {
		for (int i = 0; i < times; i++) {
			findyourletters[count++] = c;
		}
	}

	public static char[] getLetters() {
		// letters worth 1 point: E, A, I, O, N, R, T, L, S, U
		addChar(lettersArray, 'e', 1);
		addChar(lettersArray, 'a', 1);
		addChar(lettersArray, 'i', 1);
		addChar(lettersArray, 'o', 1);
		addChar(lettersArray, 'n', 1);
		addChar(lettersArray, 'r', 1);
		addChar(lettersArray, 't', 1);
		addChar(lettersArray, 'l', 1);
		addChar(lettersArray, 's', 1);
		addChar(lettersArray, 'u', 1);
		// letters worth 2 points: D, G
		addChar(lettersArray, 'd', 1);
		addChar(lettersArray, 'g', 1);
		// letters worth 3 points: B, C, M, P
		addChar(lettersArray, 'b', 1);
		addChar(lettersArray, 'c', 1);
		addChar(lettersArray, 'm', 1);
		addChar(lettersArray, 'p', 1);
		// letters worth 4 points: F, H, V, W, Y
		addChar(lettersArray, 'f', 1);
		addChar(lettersArray, 'h', 1);
		addChar(lettersArray, 'v', 1);
		addChar(lettersArray, 'w', 1);
		addChar(lettersArray, 'y', 1);
		// letters worth 5 points: K
		addChar(lettersArray, 'k', 1);
		// letters worth 8 points: J,X
		addChar(lettersArray, 'j', 1);
		addChar(lettersArray, 'x', 1);
		// letters worth 10 points: Q,Z 
		addChar(lettersArray, 'q', 1);
		addChar(lettersArray, 'z', 1);


		char[] s = new char[10];

		int n = 0;
		for (int i = 0; i < 10; i++) {
			while (true) {
				n = (int) (Math.random() * 26);
				// drawn letter is set to 'N' so that this
				//this letter is drawn only once
				if (lettersArray[n] != 'N') {
					s[i] = lettersArray[n];
					// set the letter to "" so that
					lettersArray[n] = 'N';
					break;
				}
			}
		}
		return s;
	}

	private static void addChar(char[] letterArr2, char c) {
		// TODO Auto-generated method stub
		
	}

	public static void main(String[] args) {

So is there an easier way to generate the 10 random letters and prevent those letters not used up to be seen in the next round for the player and letters that are used up to be generated randomly?

Try to reply as soon as possible!!

Thanks for the help!

if you have some logic to "prevent those letters not used up to be seen" it's not random at all.
If it were random it wouldn't matter whether a letter had already been used or not.

Easiest is to just use the Random class to draw new values, and convert those values to what you want to show on the spot.

HI!
Yes..he's right..like in c++ language..a randomize function is available.why not try to do random class in this problem, then convert the values to a character..use IntegerParseint

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.