There will be 10 namestores. A random name is chosen from amongthese10names

Özde

How can there be a namestore of 10 names in this code? A random name is chosen from among these 10 names. how can i add?

27 Views
About the Author
import java.io.*;
import java.util.ArrayList;
import java.util.Random;
public class kelimebul
{
        public static void main(String args[])throws IOException
        {
   
            
        	String kelime = "hakan";int i,tahmin=0,anahtar=0,dogru=2;
                String eldevar[] = new String[kelime.length()];
                Random rastgele = new Random();  

                System.out.println("Kelimeyi bulmak için 5 yanlış hakkınız var.");
                BufferedReader klavye = new BufferedReader(new InputStreamReader(System.in));

                for (i = 0; i < kelime.length(); i++)
                {
                        eldevar[i] = "_ ";

                }

                finish:
                while(tahmin<6){
                        System.out.println("Bir harf giriniz (Kalan hakkiniz "+(5 -tahmin) +") : ");
                        String harf = klavye.readLine();
                        tahmin++;
                        for (i = 0; i < kelime.length(); i++)
                        {
                                if (kelime.charAt(i) == harf.charAt(0))
                                {
                                        eldevar[i] = harf+" ";
                                        anahtar = 1;
                                        dogru++;
                                        if (dogru == kelime.length()) { System.out.println("kelime " +kelime+"...Tebrikler..."); break finish; }
                                }
                        }
                        if (anahtar == 1) { anahtar = 0; tahmin--; }
                        for (i = 0; i < kelime.length(); i++)
                        {
                                System.out.print(eldevar[i]);

                        }
                        System.out.println();
                }
                if (dogru != kelime.length()) { System.out.println("Uzgunum... Dogru yanit " + kelime); }

        }
}
rproffitt 2,000 "Nothing to see here." Moderator

Reusable Code Snippet means ready for others to use. Even your title calls that out.

Change your post type and elaborate what your question is.

Be a part of the DaniWeb community

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