0% found this document useful (0 votes)
55 views5 pages

Print Unique Characters: Sample Input 1

This program prints all the unique characters in a given sentence. It first checks if the sentence contains only alphabets. If not, it displays "Invalid Sentence". Otherwise, it checks each character for uniqueness and prints any unique characters found, or displays "No unique characters" if none are found.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views5 pages

Print Unique Characters: Sample Input 1

This program prints all the unique characters in a given sentence. It first checks if the sentence contains only alphabets. If not, it displays "Invalid Sentence". Otherwise, it checks each character for uniqueness and prints any unique characters found, or displays "No unique characters" if none are found.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Print unique characters

Write a program to print all the unique characters in a given sentence. 

The sentence should have only alphabets .

If the sentence is not valid display the message "Invalid Sentence".

If unique characters are not found print "No unique characters".

If unique characters are found print those characters as shown in sample output.

Sample Input 1:
Enter the sentence:
java is an object oriented programming language

Sample Output 1:
Unique characters:
v
s
b
c
d
p
l
u

Sample Input 2:
Welcome to 12house

Sample Output 2:
Invalid Sentence

import java.util.*;

public class UniqueChar

static int check(char A[], int l)


{

for(int i = 0; i < l; i++)

if((A[i] >= 0 && A[i] <= 31) || (A[i] >= 33 && A[i] <= 64) || (A[i] >= 91 && A[i] <= 96) || (A[i] >=
123 && A[i] <= 127))

return 1;

return 0;

public static void main(String args[])

Scanner Sc = new Scanner(System.in);

String s;

System.out.println("Enter the sentence:");


s = Sc.nextLine();

char A[] = s.toCharArray();

char b[]=new char[100];

int l = A.length;

int k=0;

int flag = 0;

if(check(A, l) == 1)

System.out.println("Invalid Sentence");

else

for(int i = 0; i < l; i++)

int count = 0;

for(int j = 0; j < l; j++)


{

if(A[i] == A[j])

count++;

if(count > 1)

break;

if(count == 1)

flag = 1;

b[k++]=A[i];

}
}

if (flag == 0 )

System.out.println("No unique characters");

if(k>=1){

System.out.println("Unique characters:");

for(int i=0;i<k;i++){

System.out.println(b[i]);

You might also like