PROGRAM
Write a program to accept a string and output the word having the
maximum no. of vowels in it.
ALGORITHM :-
STEP 1:- START
STEP 2:- Input string s
STEP 3:- Declare int c,len, l, String sr[],str, char ar.
Initialize max=0,a=0,i=0,j=0
STEP 4:- sr[][Link](" ")
STEP 5:- Assign l=[Link]
STEP 6:- Check i<l then
Assign c=0, str=sr[i]
Assign len=[Link]()
STEP 7:- Check j<len then
Assign ar=[Link](j)
Check ar==A||ar==E||ar==I||ar==O||ar==U||ar==a||ar==e||ar==i||ar==o||
ar==u then
Increment c++
STEP 8:- Increment j++
STEP 9:- Check max<c then
Assign max=c , a=i
STEP 10:- Increment i++
STEP 11:- Print sr[a]
STEP 12:- END
CODING:-
class word
{ void accept(String s)
{ int max=0,a=0,l,i,c,len,j;
String sr[]=[Link](" "); //to split the string
l=[Link]; //to determine no. of words
for(i=0;i<l;i++)
{ c=0;
String str=sr[i];
len=[Link](); //to find the length of word
for(j=0;j<len;j++)
{ char ar=[Link](j); //to extract each character if(ar=='A'||
ar=='E'||ar=='I'||ar=='O'||ar=='U'||ar=='a'||ar=='e'||ar=='i'||ar=='o'||ar=='u')
//to check whether character is vowel or not
c++; //count vowels in each word
if(max<c) /* to determine word
{ max=c; having maximum no. of vowels */
a=i;
}}
[Link]("Maximum vowels are in "+sr[a]);
}}
OUTPUT:-
Input-switzerland is a beautiful place
Result- Maximum vowels are in beautiful
PROGRAM
Write a program to accept a string and a substring and output the
no. of occurrence of the given substring in the main string.
ALGORITHM :-
STEP 1:- START
STEP 2:- Input String s, sr
STEP 3:- Declare int l, String str[]. Initialize c=0,i=0
STEP 4:- str[]=[Link](" ")
STEP 5:- Assign l=[Link]
STEP 6:- Check i<l then
Check str[¡].equals sr then
Increment c++
STEP 7:- Increment i++
STEP 8:- Print c
STEP 9:- END
CODING:-
class find
{ void accept(String s,String sr)
{ int c=0,l,i;
String str[]=[Link](" ");
l=[Link];
for(i=0;i<l;i++)
{ if(str[i].equals(sr))
c++;
[Link]("Occurence of substring "+sr+" in string "+s+" is "+c+"
times");
}}
OUTPUT:-
Input- String :- defeat the defeat before defeat defeats you
Substring :- defeat
Result- Occurence of substring defeat in string defeat the defeat before defeat
defeats you is 3 times
PROGRAM
Write a program to accept 50 no. within the method itself and print
the following:
No. of positive values
No. of negative values
No. of odd values
No. of even values
No. of zeros
ALGORITHM :-
STEP 1:- START
STEP 2:- Declare i. Initialize a[50], pos=0, neg=0, even =0, odd=0, zero=0
STEP 3:- Print "Enter 50 elements "
STEP 4:- Initialize i=0
STEP 5:- Check i<50 then
Input a[i]
Increment i++
STEP 6:- Initialize i=0
STEP 7:- Check i<50 then
Check a[i]>0 then
Increment pos++
Otherwise neg++
Increment i++
STEP 8:- Initialize i=0
STEP 9:- Check i<50 then
Check a[i]%2==0 then
Increment even++
Otherwise odd ++
Increment i++
STEP 10:- Initialize i=0
STEP 11:- Check i<50 then
Check a[i]==0 then
Increment zero++
Increment i++
STEP 12:- Print pos, neg, even , odd, zero
STEP 13:- END
CODING:-
import [Link].*;
class number
{ void display()throws IOException
{ DataInputStream d=new DataInputStream([Link]);
int i,pos=0,neg=0,even=0,odd=0,zero=0;
int a[]=new int[50];
[Link]("Enter 50 numbers ");
for(i=0;i<50;i++)
{ a[i]=[Link]([Link]());
for(i=0;i<50;i++)
{ if(a[i]>0)
pos++;
else
neg++;
for(i=0;i<50;i++)
{ if(a[i]%2==0)
even++;
else
odd++;
for(i=0;i<50;i++)
{ if(a[i]==0)
zero++;
[Link]("No. of positive numbers are:- "+pos);
[Link]("No. of negative numbers are:- "+neg);
[Link]("No. of even numbers are:- "+even);
[Link]("No. of odd numbers are:- "+odd);
[Link]("No. of zeros are:- "+zero);
}}
OUTPUT:-
Input- Enter 50 numbers
23 23 87 66 72
45 56 -9 0 -66
-89 0 78 -56 77
67 -53 0 -52 22
-34 1 -40 45 0
0 77 34 43 2
56 -97 88 -44 -4
21 0 10 81 7
-67 85 -23 90 3
0 43 67 2 -18
Result:-
No. of positive numbers are:- 29
No. of negative numbers are:- 14
No. of even numbers are:- 26
No. of odd numbers are:- 24
No. of zeros are:- 7