Computer Science, asked by rhssrivalli, 7 months ago

Write a Java program to input a string and check whether it is a unique string or not.
(A unique string is a word in which none of the letters are repeated.
Example:Computer)​

Answers

Answered by pratimakumari282006
2

Answer:

// Java program to illustrate string with

// unique characters using brute force technique

import java.util.*;

class GfG {

boolean uniqueCharacters(String str)

{

// If at any time we encounter 2 same

// characters, return false

for (int i = 0; i < str.length(); i++)

for (int j = i + 1; j < str.length(); j++)

if (str.charAt(i) == str.charAt(j))

return false;

// If no duplicate characters encountered,

// return true

return true;

}

public static void main(String args[])

{

GfG obj = new GfG();

String input = "GeeksforGeeks";

if (obj.uniqueCharacters(input))

System.out.println("The String " + input + " has all unique characters");

else

System.out.println("The String " + input + " has duplicate characters");

}

}

Similar questions