To Calculate Length of Vowel Words
To Calculate Length of Vowel Words
Accept a paragraph of text consisting of sentences that are terminated by either ’.’(full stop), ‘.’ (full
stop), ‘,’ (comma), ‘!’(exclamation mark) or a ‘?’ (question mark) followed by a space. Assume that
there cab be maximum 10 sentences in a paragraph. Convert the paragraph in capitals. Write a
program to perform the following using the sample data and some random data:
(a)Arrange the sentences in alphabetical order or words, sentence by sentence.
(b)Separate the words which begin with a vowel.
Examples
(1) INPUT: HELLO! HOW ARE YOU? I AM FINE, PLEASE COME AND ATTEND THE PARTY.
OUTPUT: HELLO! ARE HOW YOU? AM FINE I, AND ATTEND COME PARTY PLEASE THE
VOWEL WORDS: ARE, I, AM, AND, ATTEND
(2) INPUT: I LOVE MY COUNTRY INDIA.
OUTPUT: COUNTRY I INDIA LOVE MY.
VOWEL WORDS: I, INDIA
Algorithm
Start.
Enter Sentence.
Calculate its length.
Run a loop.
If Smallcase letter alphabet found then convert to Uppercase.
Run a loop.
Calculate number of words by calculating number of spaces.
Run a loop.
Sort in Alphabetical Order by using Bubble Sort and compareTo() function.
Run a loop.
Check first alphabet of each word is Vowel or not.
If Vowel then store the word in String ‘w’ using while loop.
Finally print Vowel Words.
Variable Description
INPUT: HELLO! HOW ARE YOU? I AM FINE, PLEASE COME AND ATTEND THE PARTY.
OUTPUT: HELLO! ARE HOW YOU? AM FINE I, AND ATTEND COME PARTY PLEASE THE
VOWEL WORDS: ARE,I,AM,AND,ATTEND
Question 2:
The input in this question will consist of a number of lines of englih text consisting oh the letters of
the English alphabet, the punctuation marks ‘ ‘ ‘,’.’,’:’,’;’ and white space characters(blank, new line).
Your task is to print the words of the text in reverse order without any punctuation marks other than
blanks.
For example consider the following input text:
This is a sample piece of text to illustrate this question.
If u are smart you will solve this right.
The corresponding output would read as:
Right this solve will you smart are you if question this illustration to text of piece sample a is this
Input format:
This first line of input contains a single integer n(<=20), indicating the number of lines in the input.
This is followed by n lines of input text. Each line should accept a maximum of 80 characters.
Output format:
Output the text containing the input lines in reverse order without punctuations except blanks as
illustrated above.
Test your program for the following data and some random data.
Sample data:
Input:
2
Emotions controlled and directed to work, is character.
By Swami Viveknanda.
Output:
Vivekanada Swami By character is work to directed and controlled Emotions
Input:
1
Do not judge a bool by its cover page.
Output:
Cover its by book a judge not Do
Algorithm
i) Start
ii)Enter number lines
iii) Enter sentences one by one in an array
iv) Run a loop and store the sentences is a single string.
v) Calculate its length
vi) Run a loop
vii) pick up character and check for space.
viii) if space found store till next space using while loop
ix) Store in reverse order
x) Print the final string
Variable Description
Variable Data Type Description
Nl Int To get number of lines
I Int To run a loop
L Int To calculate length
P Int To get position after space
N String To concatenate the sentences
W String To get words after space
S String To get the final string
H Char To pick up characters
Program
import java.io.*;
class Pg_381_Q170
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
intnl=0,i,l=0,p=0;
String n="",w="",s="";
char h=0;
System.out.println("Enter number of Lines:");
nl=Integer.parseInt(in.readLine());
String a[]=new String[nl];
System.out.println("Enter Sentences one by one");
for(i=0;i<nl;i++)
{
a[i]=in.readLine();
}
for(i=0;i<nl;i++)
{
n=n+' '+a[i];
}
System.out.println(n);
l=n.length();
for(i=0;i<l;i++)
{
w="";
h=n.charAt(i);
p=i+1;
if(h==' ')
{
h=n.charAt(i+1);
while(Character.isLetter(h))
{
w=w+h;
h=n.charAt(++p);
}
}
s=w+" "+s;
}
System.out.println("OUTPUT:"+s);
}
}
Input:
2
Emotions controlled and directed to work, is character.
By Swami Viveknanda.
Output:
Vivekanada Swami By character is work to directed and controlled Emotions
Input:
1
Do not judge a bool by its cover page.
Output:
Cover its by book a judge not Do
Question 3:
Write a program to input a natural number less than 10000 and then output if in words. Test your
program for the following set of data:
Input: 29
Output: TWENTY NINE
Input: 17
Output: SEVENTEEN
Input: 119
Output: ONE HUNDRED NINETEEN
Input: 225
Output: TWO HUNDRED TWENTY FIVE
Algorithm
Start
Store the required string in various arrays
Input the number
Check if <11
Get position and print the string
Check if 11 to 20
Get position from b and print string
Check if 20-99
Get positions from a and c anp add and print
Repeat this checking process and cget positions from reqiured string and print
Variable Description
Variable Data Type Description
k Int To get n%100
n Int To get the number
P Int To get n/1000
a[] string To store One-Ten
b[] string To store Eleven-Nineteen
c[] string To store Twenty-Ninety
d[] string To store 1 Hundred-9 Hundred
e[] string To store 1 Thousand-9 Thousand
Program
import java.io.*;
class Pg_382_Q174
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
String a[]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
String c[]={"","Ten","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
String
b[]={"","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Ninete
en"};
String d[]={"","One Hundred","Two Hundred","Three Hundred","Four Hundred","Five
Hundred","Six Hundred","Seven Hundred","Eight Hundred","Nine Hundred"};
String e[]={"","One Thousand","Two Thousand","Three Thousand","Four Thousand","Five
Thousand","Six Thousand","Seven Thousand","Eight Thousand","Nine Thousand"};
int k=0,n=0,p=0;
System.out.println("Input: ");
n=Integer.parseInt(in.readLine());
System.out.println("Output:");
if(n<11)
{
System.out.println(a[n]);
}
else if((n>10)&&(n<21))
{
System.out.println(b[n%10]);
}
else if((n>20)&&(n<100))
{
System.out.println(c[n/10]+" "+a[n%10]);
}
else if((n>99)&&(n<1000))
{
k=n%100;
if(k<11)
{
System.out.println(d[n/100]+" "+a[k%10]);
}
else if((k>10)&&(k<21))
{
System.out.println(d[n/100]+" "+b[k%10]);
}
else
{
System.out.println(d[n/100]+" "+c[k/10]+" "+a[k%10]);
}
}
else
{
p=n%1000;
k=p%100;
if((p/100==0)&&((p%100)/10==0))
{
System.out.println(e[n/1000]+" "+a[n%10]);
}
else
{
if(k<11)
{
System.out.println(e[n/1000]+" "+d[p/100]+" "+a[k%10]);
}
else if((k>10)&&(k<21))
{
System.out.println(e[n/1000]+" "+d[p/100]+" "+b[k%10]);
}
else
{
System.out.println(e[n/1000]+" "+d[p/100]+" "+c[k/10]+" "+a[k%10]);
}
}
}
}
}
Input: 29
Output: TWENTY NINE
Input: 17
Output: SEVENTEEN
Input: 119
Output: ONE HUNDRED NINETEEN
Input: 225
Output: TWO HUNDRED TWENTY FIVE
Question 4:
A simple encryption system uses a shifting process to hide a message. The value of the shift can be in
the range 1 to 26(otherwise error “INVALID ENTRY” should appear). Forexample shift 7 means that
A=U,B=V,C=W etci.e
TEXT: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
CODE: U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
An extra space is added to the end of the string. To make things a little more difficult, spaces within
the original text are replaced with QQ before the text is encrypted. Double Q(QQ) was selected
because no English word ends with Q or contains QQ.
Additionally the coded message is printed in the blocks of six characters separated by spaces. The
last block might not contain six characters. Write a program that takes the coded text(less than 100
characters), the shift value and prints the decoded original text. Your program must reject any non-
valid value for shift. Assume all characters are in upper case.
Input coded text: UHINBYLKKQCHHYLKK
Shift: 7
Decoded text: ANOTHER WINNER
Input coded text: RUIJGGEVGGBKSAGG
Shift: 11
Decoded text: BEST OF LUCK
Input coded text: RUIJGGEVGGBKSAGG
Shift: 29
Invalid Shift Value.
Algorithm
Start
Enter Code.
Enter Shift value.
Check if shift value is <=26 or not.
If exceeds then print “Invalid Shift Value”.
If not then calculate length.
Get characters.
Get its ASCII value.
Add the shift value.
If exceeds range then subtract 64.
Print the required decode.
Variable Description
Variable Data Type Description
i Int To run a loop
l Int To calculate length
d Int To store value after adding shift
f Int To get ASCII of characters
s Int Shift value
n String To store Code
h Char To get characters
t Char Get character to check for
space
Program
import java.io.*;
class Pg_384_Q178
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
int i=0,l=0,d=0,f=0,s=0;
String n;
char h=0,t=0;
System.out.println("Enter Code");
n=in.readLine();
System.out.println("Shift Value");
s=Integer.parseInt(in.readLine());
l=n.length();
if((s>=1)&&(s<=26))
{
for(i=0;i<l;i++)
{
h=n.charAt(i);
f=((int)h);
t=n.charAt(i+1);
if((h==t)&&((h=='K')||(h=='G')))
{
System.out.print(" ");
i=i+1;
}
else
{
d=(f+s)%90;
if(d>=65)
System.out.print((char)(d-1));
else
System.out.print((char)(63+d));
}
}
}
else
System.out.println("Invalid Shift Value");
}
}
Input coded text: UHINBYLKKQCHHYLKK
Shift: 7
Decoded text: ANOTHER WINNER
Input coded text: RUIJGGEVGGBKSAGG
Shift: 11
Decoded text: BEST OF LUCK
Input coded text: RUIJGGEVGGBKSAGG
Shift: 29
Invalid Shift Value.
Question 5:
A new advanced Operating System, incorporating the latest hi-tech features has been designed by
Opera Computer Systems.
The task of the generating copy protection codes to prevent software privacy has been entrusted to
the Security Department.
The Security Department has decided to have codes containing a jumbled combination of alternate
uppercase letters of the alphabet starting from AuptoB (namely A,C,E,G,I,K). The code may or may
not be in the consecutive series of alphabets.
Each code should not exceed 6 characters and there should be no repetition of characters. If it
exceeds 6 characters, display an appropriate error massage.
Write a program to input a code and its length. At the first instance of an error display “Invalid”
stating the appropriate reason. In case of no error, display the message “Valid”.
Test your program for the following data and some random data.
Sample Data
Input:
n=4
ABCE
Output: Invalid! Only alternate letters permitted!
Input:
n=4
AcIK
Output: Invalid! Only upper case letters permitted!
Input:
n=4
AAKE
Output: Invalid! Repetition of characters not permitted!
Input:
n=7
Output: Error! Length of string should not exceed 6 characters!
Input:
n=4
AEGIK
Output: Invalid! String length not the same as specified!
Input:
n=3
ACE
Output: Valid
Input:
n=5
GEAIK
Output: Valid
Algorithm
Store required alphabets in character array
Enter value of n
If n>6
Print appropriate massage
ELse enter code
Calculate its length
If(n!=l)
Print the appropriate message
Else check for lower case
If found print appropriate message
Else check for repetition or invalid characters
xii) If found print appropriate message
xiii) Else print “Valid”
Variable Description
Variable Data type Description
i int To run a loop
j Int To run inner loop
v Int To calculate no. of vowel words
t Int Use as a flag
n Int To get the value
u Int To get ASCII code
m Int To store words
y Int Use as a flag
c String To store Code
a[] Char To store the alternate alphabets
h Char To pick up characters
k Char To get alphabet of string
hh Char To pick up characters
Program
import java.io.*;
class Pg_388_Q183
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
inti,j,v=0,t=0,l,n,u=0,m=0,y=0;
String c="";
char a[]={'A','C','E','G','I','K'};
char h=0,k=0,hh=0;
System.out.println("n= ");
n=Integer.parseInt(in.readLine());
if(n>6)
{
System.out.println("Error! Length of string should not exceed 6 characters!");
}
else
{
System.out.println("CODE ");
c=in.readLine();
l=c.length();
if(l!=n)
{
System.out.println("Invalid!String length not the same as specified!");
}
else
{
for(i=0;i<l;i++)
{
h=c.charAt(i);
u=((int)(h));
if(u>=97)
{
t=1;
break;
}
}
}
if(t==1)
{
System.out.println("Invalid! Only upper case letters permitted!");
}
else
{
t=0;
for(i=0;i<l;i++)
{
t=0;
h=c.charAt(i);
for(j=0;j<6;j++)
{
k=a[j];
if(k==h)
{
t++;
for(m=0;m<l;m++)
{
hh=c.charAt(m);
if(hh==k)
{
y++;
}
}
if(y>1)
{
t=2;
}
y=0;
}
y=0;
}
if(t>1)
{
System.out.println("Invalid! Repetition of characters not permitted!");
break;
}
else if(t==0)
{
System.out.println("Invalid! Only alternate letters permitted!");
break;
}
else
{
v++;
}
}
if(v==n)
{
System.out.println("Valid");
}
}
}
}
}
Input:
n=4
ABCE
Output: Invalid! Only alternate letters permitted!
Input:
n=4
AcIK
Output: Invalid! Only upper case letters permitted!
Input:
n=4
AAKE
Output: Invalid! Repetition of characters not permitted!
Input:
n=7
Output: Error! Length of string should not exceed 6 characters!
Input:
n=4
AEGIK
Output: Invalid! String length not the same as specified!
Input:
n=3
ACE
Output: Valid
Input:
n=5
GEAIK
Output: Valid