Page 392 - Computer science 868 Class 12
P. 392
Unique()
{
word="";
len=0;
}
void acceptword()
{
Scanner sc= new Scanner(System.in);
System.out.println(“Enter a word”);
word=sc.next().toUpperCase();
}
boolean checkUnique()
{
char ch1,ch2;
len=word.length();
ch1=word.charAt(0);
ch2=word.charAt(word.length()-1);
if(“AEIOU”.indexOf(ch1)!=-1 && "AEIOU".indexOf(ch2)!=-1)
return true;
else
return false;
}
void display()
{
if(checkUnique())
System.out.println(word +" is a Unique word");
else
System.out.println(word +"is not Unique word");
}
public static void main()
{
Unique ob = new Unique();
ob.acceptword();
ob.display();
}
}
/* OUTPUT
Enter a word
ARoRA
ARORA is a Unique word
Enter a word
Animal
ANIMALis not Unique word
(ii) Design a class NoRepeat which checks whether a word has no repeating alphabets in it. Example: COMPUTER has no repeated
alphabets but SCIENCE has repeated alphabets. [ISC 2022]
The details of the class are given below:
Class name : NoRepeat
Data Members/Instance variables
word : to store a word
len : to store the length of the word
Methods/Member functions
NoRepeat(String wd) : parameterised constructor to initialise word=wd
boolean check() : checks whether a word has no repeated alphabets and returns
true else returns false
390390 Touchpad Computer Science-XII

