Okay so I am making a code which will ask for a user input and then make a pattern out of it (case insensitive) the first code works however it only checks if the last variable in the string is the same to the current variable in the string
public String makePattern() { char[] charInput=userInput.toCharArray(); String output ="A"; int codeValue=65; for(int increment = 1; increment <= charInput.length-1;increment++) { if((int)charInput[increment] == (int)charInput[increment-1]) { } else { codeValue = codeValue+1; } output = output+Character.toString((char)codeValue); } return output; }
This next code totally breaks my code (it was my attempt to make it check the whole string instead of the last variable
public String makePattern() { char[] charInput=userInput.toCharArray(); String output ="A"; int codeValue=65; for(int increment = 1; increment <= charInput.length-1;increment++) { for(int checkString = 0; checkString < increment; checkString++) { if((int)charInput[increment] == (int)charInput[checkString]) { } else { codeValue = codeValue+1; } output = output+Character.toString((char)codeValue); } } return output; }