Page 1 of 1

I have attached a program written in Java, for string exercises which answers the question, Write a program to eliminate

Posted: Sat May 14, 2022 7:10 pm
by answerhappygod
I have attached a program written in Java, for string
exercises which answers the question,
Write a program to eliminate a series of characters
entered by the user. Use the same approach as the remove vowels
program. (Do not use replace function)
// Java program for printing sentence
// without repetitive vowels
import java.io.*;
import java.util.*;
import java.lang.*;
class GFG
{
// function which
returns
// True or False
for
// occurrence of a
vowel
static boolean is_vow(char
c)
{
// this
compares vowel
// with
character 'c'
return
(c == 'a') || (c == 'e') ||
(c
== 'i') || (c == 'o') ||
(c
== 'u');
}
// function to
print
// resultant string
static void removeVowels(String
str)
{
// print
1st character
System.out.print(str.charAt(0));
// loop
to check for
// each
character
for (int
i = 1;
i
< str.length(); i++)
//
comparison of
//
consecutive characters
if
((!is_vow(str.charAt(i - 1))) ||
(!is_vow(str.charAt(i))))
System.out.print(str.charAt(i));
}
// Driver Code
public static void main(String[]
args)
{
String
str = "geeks for geeks";
removeVowels(str);
}
}
Using Java, write a modular program and integrate (Procedure
type parameter passing) for the question posted above.
Thankyou.