Sunday, January 30, 2022

A Program to check if a string is unique or not

eg:Sample Input:COMPUTER
Sample Output:Unique string
import java.io.*;
class A
{
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     String str1;
     int i,j,len;
     void take() throws Exception
     {
          System.out.print("\nEnter the sentence: ");
          str1=br.readLine();
          len=str1.length();
          for(i=0;i<len-1;i++)
          {
               for(j=i+1;j<len;j++)
               {
                   if(str1.charAt(i)==str1.charAt(j))
                   break;
                }
                if(j<len)
                break;
            }
            if(i<len-1)
            System.out.print("\nNot Unique character string.");
            else
            System.out.print("\nUnique character string.");
        }
    }
  

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner