Java Forums
Our Goal is to achieve and build a community. Even if there is nobody on the forum, please register. If we have a small community, people will see we have at least people and they will register. Any people please register!

Cheers,
Slick Java (Owner + Admin)
Java Forums
Our Goal is to achieve and build a community. Even if there is nobody on the forum, please register. If we have a small community, people will see we have at least people and they will register. Any people please register!

Cheers,
Slick Java (Owner + Admin)
Java Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Java Forums

Share your Java programming ideas here.
 
HomeLatest imagesSearchRegisterLog in
Our Goal is to achieve and build a community. Even if there is nobody on the forum, please register. If we have a small community, people will see we have at least people and they will register. Any people please register! Cheers, Slick Java (Owner + Admin)
We are also looking for moderators and admins.

 

 Homework help - pairs of vowels to asterisks

Go down 
AuthorMessage
Slick Java
Admin
Admin
Slick Java


Posts : 9
Points : 10008193
Join date : 2013-03-15
Age : 23

Homework help - pairs of vowels to asterisks Empty
PostSubject: Homework help - pairs of vowels to asterisks   Homework help - pairs of vowels to asterisks Icon_minitimeTue Mar 19, 2013 2:28 pm

Hello, I have a homework assignment on changing pair of vowels to asterisks.
I have so far achieved changing a single vowel into a asterisk.
I need help on changing pairs of vowels into asterisks.
eg. bookkeeping => b**k**ping not b**kk**p*ng

Output (single vowel):

Type in a word to protect
bookkeeping
b**kk**p*ing

Code:

import java.util.*;
public class HomeworkV03 {
   
    private String chars;
    private Scanner scan = new Scanner(System.in);
    private char[] vowels = {'a','e','i','o','u'};
   
   
   
    public static void main(String args[])
    {
        HomeworkV03 h = new HomeworkV03();
        h.askClient();
        h.printVowels();
    }
   
    public void askClient()
    {
        System.out.println("Type in a word to protect");
        chars = scan.next();
    }
   
    public void printVowels()
    {
        int a = 0;
        char c;
 
       
        for (a = 0; a < chars.length(); a++)
        {
               
           
                c = chars.charAt(a);
                boolean isVowel = isVowel(c);
               
 
               
                if(isVowel )
                {
                   
                    System.out.print("*");
                   
                }
                else
                {
                    System.out.print(c);
                }
           
          }
       
        }
 
    private boolean isVowel(char c)
    {
        int i = 0;
        boolean vowel = false;
       
       
        for (i = 0; i < 5; i++)
        { 
                if(c == vowels[i])
                {
                    vowel = true;
                } 
   
        }
           
        return vowel;
    }
}

Thanks,

Slick Java
Back to top Go down
https://java.forumotion.co.uk
 
Homework help - pairs of vowels to asterisks
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Java Forums :: New to Java :: Problems + Questions-
Jump to: