i can't get it to work this code for Deja Vu why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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"); } } }

27th Oct 2021, 4:18 AM
Killiam Chances
Killiam Chances - avatar
2 Answers
0
Your conditions are not inside the while loop. there are lots of bugs, and logic error. https://code.sololearn.com/cRyrscxrobCp/?ref=app
27th Oct 2021, 4:53 AM
ACE
ACE - avatar
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
27th Oct 2021, 11:06 AM
zemiak