Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving all non-unique letters from a char [] array for hangman
    primarykey
    data
    text
    <p>I am having trouble understanding how to remove a letter from a char array here is my code </p> <pre><code>import java.util.Random; import java.util.Scanner; public class Main { public static void main(String [] args) { start(); } public static void start() { Scanner scan = new Scanner(System.in); Random rand = new Random(); String [] Words = {"Dog","cat","Food","Bacon","Turkey","hood","poo","Good","look"}; String RandomWord = Words[rand.nextInt(Words.length)]; char [] array = RandomWord.toCharArray(); boolean [] parrallelArray = new boolean[array.length]; int i = 0; int placeholder = 0; System.out.println(findUniqueLetters(array)); char input = 0; while(i&lt;findUniqueLetters(array)){ i++; System.out.println("You have a "+RandomWord.length()+" Word "+RandomWord); System.out.println("Guess a letter : "); input = scan.next().charAt(0); for(int j = placeholder; j&lt;array.length;j++){ if(input == array[j]){ j++; placeholder = j; System.out.println("You got it right"); break; } else if(!(input ==array[j])){ j++; placeholder = j; System.out.println("You got it wrong"); break; } } } System.out.println("You have wasted all your tries!"); } public static int findUniqueLetters(char [] a){ int Unique = 1; for(int i = 1; i&lt;a.length;i++){ if(!(a[i] == a[i-1])){ Unique++; } } return Unique; } } </code></pre> <p>Is there another way to do this or is deleting it the only way to do this? I have tried to switch the repeated letter in the array with the non repeated one in the array but that only works for some words.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload