Write a Java-program to print unique(distinct (or non-repeating characters) ) characters from the string ?

Write a Java-program to print unique(distinct (or non-repeating characters) ) characters from the string ?

Program
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		int x,y;
		String s;
		
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter String :");
		s=sc.nextLine();
		for (x = 0; x < s.length(); x++)
	    {
	        int flag = 0;
	        for (y = 0; y < s.length(); y++)
	        {
	            // checking if two characters are equal
	            if (s.charAt(x) == s.charAt(y) && x != y) 
	            {
	                flag = 1;
	                break;
	            }
	        }
	        if (flag == 0)
	            System.out.print(s.charAt(x));
	    }
	}

}
	

Output:

Enter String : sateesh
ath





More Questions


13 . Write a Java-program to print duplicate characters from the string ?
14 . Write a Java-program to print unique(distinct (or non-repeating characters) ) characters from the string ?
15 . Write a java program How to check if two strings are anagrams of each other?
16 . How to reverse a string in Java without using the reverse method ?
17 . How to count the occurrence of the given character in a string?
18 . How to check if a string is a palindrome?
19 . How to count the number of words in a given string sentence?
20 . How to reverse the words from the given string sentence?
21 . How to swap two strings without using the third variable?