Results 1 to 9 of 9
  1. #1
    dienesh77 is offline Member
    Join Date
    Feb 2011
    Posts
    32
    Rep Power
    0

    Default changing letters in strings

    How can I replace all the vowels in a string by 2 characters higher than the original( i.e. 'a' is replaced by 'c', and 'e' replaced by 'g'.... etc.) Using if/else statements. much help appreciated thanks.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You can add numbers to a character, so if you have char 'a' and add 2 it should produces char 'c'. So you just need to use if statements to check if an item is a vowel and change if it is.

  3. #3
    dienesh77 is offline Member
    Join Date
    Feb 2011
    Posts
    32
    Rep Power
    0

    Default

    how can I do this in a string?

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    string.charAt(index)

    for example
    Java Code:
    String hi = "hi";
    hi.charAt(0); //'h'
    hi.charAt(1); // 'i'

  5. #5
    dienesh77 is offline Member
    Join Date
    Feb 2011
    Posts
    32
    Rep Power
    0

    Default

    well in my case since the user input a string, would i use a counter to go through the string to find the vowels? if so how can i tell the counter when it reaches the end of the string?

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Do you know how to use for loops yet?

  7. #7
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by dienesh77 View Post
    if so how can i tell the counter when it reaches the end of the string?

    Use the String.length() method for this. Something like,

    Java Code:
            String s = "test";
    	for (int i = 0; i < s.length(); i++) {
    	// Your logic
    	}

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  8. #8
    dienesh77 is offline Member
    Join Date
    Feb 2011
    Posts
    32
    Rep Power
    0

    Default

    bump help pls

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,537
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dienesh77 View Post
    bump help pls
    Have you read the API documentation for the String class? It has methods that can replace parts of a String.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 0
    Last Post: 08-14-2010, 10:09 AM
  2. What does the letters mean?
    By mustachMan in forum New To Java
    Replies: 3
    Last Post: 02-11-2010, 09:50 PM
  3. Need help with counting letters
    By mrdestroy in forum New To Java
    Replies: 15
    Last Post: 10-22-2008, 01:33 PM
  4. text Strings to produce letters
    By dc2acgsr99 in forum New To Java
    Replies: 7
    Last Post: 01-29-2008, 08:08 PM
  5. need block letters??
    By dc2acgsr99 in forum New To Java
    Replies: 16
    Last Post: 01-29-2008, 08:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •