6 Replies - 339 Views - Last Post: 04 February 2018 - 02:22 PM Rate Topic: -----

#1 Xhertus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 03-February 18

determine a letter is vowel

Posted 04 February 2018 - 05:09 AM

public String doubleVowel(String str)
{
    String result ="";
    String vowels= "a" && "e" && "i" && "o" && "u";
    for(int i =0; i < str.length(); i++)
    {
        result+ = vowels;
    }
}



Hello, dear members. I have been working on a method which provides me to double all vowels in a string. I am new at coding and also on this forum. I thought something like that but it seems totally wrong to me. I am thinking about adding a private boolean to determine a letter is boolean or not.
Waiting for advices and some help.

Is This A Good Question/Topic? 0
  • +

Replies To: determine a letter is vowel

#2 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 693
  • View blog
  • Posts: 5,303
  • Joined: 25-December 13

Re: determine a letter is vowel

Posted 04 February 2018 - 05:27 AM

Quote

private boolean to determine a letter is boolean or not

Can you explain what that means? A value like a letter is not a boolean.
A boolean value is either true or false. A boolean value can represent a condition like a is greater than b or a is contained in abc.

When writing a program you need to have a design for it before deciding what statements to use to implement the design.
What are the steps the code needs to do to solve your problem?
When you have those steps listed, then work on the statements that are needed.
Was This Post Helpful? 0
  • +
  • -

#3 Xhertus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 03-February 18

Re: determine a letter is vowel

Posted 04 February 2018 - 05:28 AM

Ov sorry.. I mean to determine a letter is vowel or not my mistake :)
Was This Post Helpful? 0
  • +
  • -

#4 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 693
  • View blog
  • Posts: 5,303
  • Joined: 25-December 13

Re: determine a letter is vowel

Posted 04 February 2018 - 05:32 AM

Can you list the steps the method must take to solve the problem?
You need to have that list of steps before trying to write code.
Was This Post Helpful? 0
  • +
  • -

#5 Thomas1965   User is offline

  • D.I.C Regular

Reputation: 95
  • View blog
  • Posts: 366
  • Joined: 09-September 16

Re: determine a letter is vowel

Posted 04 February 2018 - 06:23 AM

One easy way to do it is to create a string with all vowels in uppercase and lowercase.
To determine if a character is a vowel you check if the indexOf method of the string returns != -1
Was This Post Helpful? 0
  • +
  • -

#6 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3550
  • View blog
  • Posts: 16,190
  • Joined: 20-September 08

Re: determine a letter is vowel

Posted 04 February 2018 - 08:18 AM

Quote

I have been working on a method which provides me to double all vowels in a string.

You could try something like
s = s.replaceAll("(?i)([aeiou])", "$1$1");

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is offline

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6553
  • View blog
  • Posts: 26,566
  • Joined: 12-December 12

Re: determine a letter is vowel

Posted 04 February 2018 - 02:22 PM

Do not use a meaningless title, "Help about code..", I have changed it for you on this occasion.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1