String Manipulation //Just cant handle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • H0kage
    New Member
    • Oct 2006
    • 6

    #1

    String Manipulation //Just cant handle

    Hello everyone got an assignment for college where i cant find the way to make
    JDeveloper to understand where the words are separated.This What
    The Assignment Asks.Any Tip or example to help me finish it would be greatly apreaciated.Tha nk you in advance.




    Following is an example of screen results that might appear, depending on the data the user inputs.

    This program asks the user for three words.

    The first letter of each word must be extracted, and then an acronym must be formed with the 3 letters of each word you have extracted.

    Enter 3 words separated by blanks: Going To Pass

    The acronym should be in this form : GTP
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by H0kage
    Hello everyone got an assignment for college where i cant find the way to make
    JDeveloper to understand where the words are separated.This What
    The Assignment Asks.Any Tip or example to help me finish it would be greatly apreaciated.Tha nk you in advance.




    Following is an example of screen results that might appear, depending on the data the user inputs.

    This program asks the user for three words.

    The first letter of each word must be extracted, and then an acronym must be formed with the 3 letters of each word you have extracted.

    Enter 3 words separated by blanks: Going To Pass

    The acronym should be in this form : GTP
    What have you done so far?

    Comment

    • H0kage
      New Member
      • Oct 2006
      • 6

      #3
      With some research in this forum and some help from a friend i managed to get a clue and solve it.Thank You for your reply :)

      This is my solution in which dont think there is an error.Feel free to correct me.



      import java.util.Scann er;

      public class String_Acronym {
      static Scanner Scanner=new Scanner(System. in);
      public static void main(String[] args) {

      System.out.prin tln("Enter 3 Words Separated With Spaces : ");
      String Word=Scanner.ne xtLine();

      String[] result = Word.split("\\s ");
      for (int x=0; x<result.length ; x++)

      System.out.prin t(result[x].charAt(0));
      System.out.prin tln();
      }
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by H0kage
        With some research in this forum and some help from a friend i managed to get a clue and solve it.Thank You for your reply :)

        This is my solution in which dont think there is an error.Feel free to correct me.



        import java.util.Scann er;

        public class String_Acronym {
        static Scanner Scanner=new Scanner(System. in);
        public static void main(String[] args) {

        System.out.prin tln("Enter 3 Words Separated With Spaces : ");
        String Word=Scanner.ne xtLine();

        String[] result = Word.split("\\s ");
        for (int x=0; x<result.length ; x++)

        System.out.prin t(result[x].charAt(0));
        System.out.prin tln();
        }
        }
        An elegant solution. Now make it a point never to forget the power of regular expressions. Mastering them now will save you a lot of code in the future.

        Comment

        Working...