0
i can't get it to work this code for Deja Vu why?
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String word=sc.nextLine(); char[]arr=word.toCharArray(); int i=0; while(i<arr.length-1){ i++; } if(arr[i]==arr[i+1]){ System.out.println("Deja Vu"); }else{ System.out.println("Unique"); } } }
2 Antworten
0
Your conditions are not inside the while loop. there are lots of bugs, and logic error.
https://code.sololearn.com/cRyrscxrobCp/?ref=app
0
while(i<arr.length-1) {
i++;
}
this loop do nothing but increases i
then one time you compare two characters in close positions together, like "aabbcc"
but there can be "abcd abcd" which are also repeating