+ 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
9 Answers
+ 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.
+ 3
Unique in what aspect!?
+ 1
Could it be that you only put the output strings the wrong way round?
0
If you only get one string, the string is always unique?
What exactly should be unique? Characters?
0
A unique string are those strings which don't have any single character repeated in that string....i hope you get it Lisa
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.
0
Ah ohkay thanks a lot Lisa
0
Thanks a lot sir Infinity i got the issue
0
Thank you so much Thineshan Panchalingam sir