+ 1

Write a program to accept a string and check whether the string is unique or not

I am not getting the output do tell me please 🥺🥺🥺 https://code.sololearn.com/cKxN1PaisSo5/?ref=app

18th Apr 2022, 8:04 AM
Nandini Bhardwaj
Nandini Bhardwaj - avatar
9 Respuestas
+ 3
import java.util.*; class Test{ public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("Enter String:"); String str = s.nextLine(); char[] array = str.toCharArray(); Set<Character> set = new HashSet<Character>(); for(char c: array){ set.add(c); } if(str.length()==set.size()) System.out.println("Unique String!!!"); else System.out.println("Not a Unique String!!!"); } } This is my approach.
18th Apr 2022, 1:13 PM
Thineshan Panchalingam
Thineshan Panchalingam - avatar
+ 3
Unique in what aspect!?
20th Apr 2022, 1:20 AM
Yusra
Yusra - avatar
+ 1
Could it be that you only put the output strings the wrong way round?
18th Apr 2022, 8:23 AM
Lisa
Lisa - avatar
0
If you only get one string, the string is always unique? What exactly should be unique? Characters?
18th Apr 2022, 8:14 AM
Lisa
Lisa - avatar
0
A unique string are those strings which don't have any single character repeated in that string....i hope you get it Lisa
18th Apr 2022, 8:16 AM
Nandini Bhardwaj
Nandini Bhardwaj - avatar
0
According to your code, all it does is check if two consecutive characters are same anywhere in the string, if yes, it will return "Unique String". Now, if you wish we could help, please specify the problem statement clearly, i.e. what a unique string really is.
18th Apr 2022, 8:23 AM
Abhishek Tandon
Abhishek Tandon - avatar
0
Ah ohkay thanks a lot Lisa
18th Apr 2022, 8:24 AM
Nandini Bhardwaj
Nandini Bhardwaj - avatar
0
Thanks a lot sir Infinity i got the issue
18th Apr 2022, 8:25 AM
Nandini Bhardwaj
Nandini Bhardwaj - avatar
0
Thank you so much Thineshan Panchalingam sir
19th Apr 2022, 3:28 AM
Nandini Bhardwaj
Nandini Bhardwaj - avatar