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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply