Computer Applications
A string is said to be ‘Unique’ if none of the letters present in the string are repeated. Write a program to accept a string and check whether the string is Unique or not. The program displays a message accordingly.
Sample Input: COMPUTER
Sample Output: Unique String
Java
Java String Handling
56 Likes
Answer
import java.util.Scanner;
public class KboatUniqueString
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = in.nextLine();
str = str.toUpperCase();
boolean isUnique = true;
int len = str.length();
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
for (int j = i + 1; j < len; j++) {
if (ch == str.charAt(j)) {
isUnique = false;
break;
}
}
if (!isUnique)
break;
}
if (isUnique)
System.out.println("Unique String");
else
System.out.println("Not Unique String");
}
}
Variable Description Table
Program Explanation
Output

Answered By
20 Likes
Related Questions
Write a program to input twenty names in an array. Arrange these names in ascending order of letters, using the bubble sort technique.
Sample Input:
Rohit, Devesh, Indrani, Shivangi, Himanshu, Rishi, Piyush, Deepak, Abhishek, Kunal, …..
Sample Output:
Abhishek, Deepak, Devesh, Himanshu, Indrani, Kunal, Piyush, Rishi, Rohit, Shivangi, …..Write a program in Java to input the names of 10 cities in a Single Dimensional Array. Display only those names which begin with a consonant but end with a vowel.
Sample Input: Kolkata, Delhi, Bengaluru, Jamshedpur, Bokaro, …….
Sample Output: Kolkata
Delhi
Bengaluru
Bokaro
….
….Write a program in Java to store 10 words in a Single Dimensional Array. Display only those words which are Palindrome.
Sample Input: MADAM, TEACHER, SCHOOL, ABBA, ………
Sample Output: MADAM
ABBA
……….
……….Write a program to accept the names of 10 cities in a single dimensional string array and their STD (Subscribers Trunk Dialling) codes in another single dimension integer array. Search for the name of a city input by the user in the list. If found, display "Search Successful" and print the name of the city along with its STD code, or else display the message "Search unsuccessful, no such city in the list".