27th Feb 2020, 8:32 PM
Эмиль Маннапов
Эмиль Маннапов - avatar
4 Réponses
+ 2
arr.add(input.nextLine()); for(int i=arr.size()-1;i>0;i--) From these two, it take a line of input, adds to ArrayList, Now size of array list is 1 only.. For loop never starts.., because i=0 > 0 false. What is the need of ArrayList? Probably, you not understood what is ArrayList... It doesnot add character by character. It adds owl elements which may be strings, numbers,... So use a string or convert input to a char array by toCharArray() method.
27th Feb 2020, 8:49 PM
Jayakrishna 🇮🇳
+ 1
import java.util.Arrays; ... ArrayList<String> arr = new ArrayList<>( Arrays.asList( input.nextLine() .split("") ) ); for(int i=arr.size()-1; i>0; i--) { for(int j=0; j<i; j++){ //not j<0 if (arr.get(j).equals(arr.get(i))) { System.out.println("Deja Vu" ); return; } }} System.out.println("Unique");
27th Feb 2020, 10:53 PM
zemiak
0
Task: If you are given a string of random letters, your task is to evaluate whether any letter is repeated in the string or if you only hit unique keys while you typing.
27th Feb 2020, 8:32 PM
Эмиль Маннапов
Эмиль Маннапов - avatar
0
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); String copied_string=""; String duplicates=""; int digit=0; int count=0; for(int i=0;i<s.length();i++) { String current=Character.toString(s.charAt(i)); if(copied_string.contains(current)) { count++; } copied_string+=current; } if(count>=1) { System.out.println("Deja Vu"); } else { System.out.println("Unique"); } } }
16th Apr 2020, 5:21 AM
kartik narang
kartik narang - avatar