Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: String Manipulations Help

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default String Manipulations Help

    I've been working at this all weekend. I'm a n00b...don't make fun.

    Obviously this works with a Tester class which is setup alright. The first object is supposed to Print only uppercase letters. I had it printing one uppercase letter and now it just returns the string. How can I print all uppercase letters? The second one is just printing the first letter. That's a far cry from printing every other letter. Anyone have any idea what I'm doing wrong on these things? I tremendously appreciate the help.

    All the best,
    Gene

     
    //******************************************
    // LetterAPI.java 
    // Written by Sanchez
    // 2013
    //*******************************************
     
    //===========================================
    // Objects of this class manipulate an inputted string.
    //===========================================
     
    import java.util.Scanner;
     
    //contains a set of methods for maniuplaing the string
    public class LetterAPI {
     
        //print only uppercase letters
        public static String bigLetters(String input) {
            String result = "";
            char cl;
            for (int i = 0; i <input.length(); i++) {
            cl=input.charAt(i);
            if (Character.isUpperCase(cl))
            input = input + cl;
            }
            return input;
     
     
    }
        //print every second letter
        public static String secondLetter(String input) {
            String result = "";
            for (int i=0; i<input.length(); i+=2) {
            input = input + input.charAt(i) + " ";
            }
            return input;
     
     
    }
         //all vowels replaced by underscores
        public static String vowelsGone(String input) {
            String vowels ="aeiouAEIOU";
            for (int i = 0; i<vowels.length();i++) {
            input=input.replace(vowels.charAt(i), '_');
            }
            return input;
     
     
    }
        //the numbers of vowels
        public static String vowelNumber(String input) {
            String result = "";
            int count = 0;
            for (int i = 0; i <input.length(); i++) {
     
                if (Character.toLowerCase(input.charAt(i)) == 'a' || Character.toLowerCase(input.charAt(i)) == 'e' || Character.toLowerCase(    input.charAt(i)) == 'i' || Character.toLowerCase(input.charAt(i)) == 'o' || Character.toLowerCase(input.charAt(i)) == 'u') {
                    count++;
                    result = count + " ";
                }
     
            }
            return result;
     
    }
        //the positions of all vowels
        public static String vowelPositions(String input) {
            String result = "";
            for (int i = 0; i <input.length(); i++) {
     
                if (Character.toLowerCase(input.charAt(i)) == 'a' || Character.toLowerCase(input.charAt(i)) == 'e' || Character.toLowerCase(input.charAt(i)) == 'i' || Character.toLowerCase(input.charAt(i)) == 'o' || Character.toLowerCase(input.charAt(i)) == 'u') {
                    result = result + i + " ";
                }
            }
            return result;
     
    }
    }


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default Re: String Manipulations Help

    In both methods you are asking for an input parameter and then you create a String result. In both methods you leave result untouched and just add to the input String passed and the return that same String.

    You are suppose to modify the result string and return the modified string to see results. Take a look at you vowelNumber() or vowelPositions() to see how they are working.

Similar Threads

  1. Replies: 6
    Last Post: June 3rd, 2013, 04:57 AM
  2. Replies: 2
    Last Post: March 28th, 2013, 09:54 AM
  3. Replies: 11
    Last Post: November 12th, 2012, 01:09 PM
  4. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  5. Replies: 3
    Last Post: June 14th, 2009, 09:31 PM

Tags for this Thread