Computer Science, asked by pratishmoses, 9 months ago

Write a program in java to input a name and check whether it is a unique name or not. A name is said to be unique in which the letters do not repeat.

Answers

Answered by poonanjagay1985
2

I'm writing a program that will print the unique character in a string (entered through a scanner). I've created a method that tries to accomplish this but I keep getting characters that are not repeats, instead of a character (or characters) that is unique to the string. I want the unique letters only.

e unique letters only.

Here's my code:

import java.util.Scanner;

public class Sameness{

public static void main (String[]args){

Scanner kb = new Scanner (System.in);

String word = "";

System.out.println("Enter a word: ");

word = kb.nextLine();

uniqueCharacters(word);

}

public static void uniqueCharacters(String test){

String temp = "";

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

if (temp.indexOf(test.charAt(i)) == - 1){

temp = temp + test.charAt(i);

}

}

System.out.println(temp + " ");

}

mark as brainlist...

Similar questions