Results 1 to 6 of 6
  1. #1
    magnolia5 is offline Member
    Join Date
    Apr 2017
    Posts
    3
    Rep Power
    0

    Default A method that suppose to return a string consisting of alternate characters

    I am a beginner at Java and currently studying foundation. I was given a practice method a week ago which i do not understand and up until now i am unable to figure out the correct method. The method is suppose to return a string consisting of alternate characters of the string <value>.

    Java Code:
     public String(String s)
    {
      StringBuilder sb =  _____ ;   
      for( _____ index =  _____ ; index  _____  _____ ;  _____ )
      {
        sb. _____  _____ ;
      }
         
       _____  _____ ;
    }
    edit: i have managed to figure out the method, thanks a lot
    Last edited by magnolia5; 04-14-2017 at 10:56 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: A method that suppose to return a string consisting of alternate characters

    You are supposed to fill in the appropriate pieces of code to make the method work. Let's say you want to print the squares of the the numbers of 1 to n. And you want to do this for the first 20 numbers (1 thru 20).

    Java Code:
    int n = _______;
    for (i = ____;  i  ____  ____; i++) {
       System.out.println(_____);
    }
    choices:
    20
    30
    <
    <=
    n
    n*n
    n*n*n
    1
    2
    3

    The answer would be
    Java Code:
    int n = 20;
    for (i = 1; i <= n; i++) {
       System.out.println(n*n);
    }
    Now do the same for your problem.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    magnolia5 is offline Member
    Join Date
    Apr 2017
    Posts
    3
    Rep Power
    0

    Default Re: A method that suppose to return a string consisting of alternate characters

    Quote Originally Posted by jim829 View Post
    You are supposed to fill in the appropriate pieces of code to make the method work. Let's say you want to print the squares of the the numbers of 1 to n. And you want to do this for the first 20 numbers (1 thru 20).
    Yes i understand that i need to fill the blanks using the codes from the options but i dont understand the method and the codes provided from the question. I am very new to Java

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: A method that suppose to return a string consisting of alternate characters

    Have you covered StringBuilder and String and their methods in class? Do you know how to construct for loops and what <=, <, == mean?

    And have you covered how to create instances of objects? Can you fill in statement #3 in your assignment?

    Regards,
    Jim
    Last edited by jim829; 04-13-2017 at 09:55 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    magnolia5 is offline Member
    Join Date
    Apr 2017
    Posts
    3
    Rep Power
    0

    Default Re: A method that suppose to return a string consisting of alternate characters

    Quote Originally Posted by jim829 View Post
    Have you covered StringBuilder and String and their methods in class? Do you know how to construct for loops and what <=, <, == mean?

    And have you covered how to create instances of objects? Can you do fill in statement #3 in your assignment?

    Regards,
    Jim
    Not yet, however i would like to get advance on my classes since i dont feel confident with my understanding with Java.
    These practice activities are given a week before the actual lessons.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: A method that suppose to return a string consisting of alternate characters

    Quote Originally Posted by magnolia5 View Post
    ... i would like to get advance on my classes ...
    Good for you! There's a marvelous resource: the first link in Jim's signature line.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 6
    Last Post: 07-09-2015, 05:16 PM
  2. Replies: 7
    Last Post: 04-02-2014, 02:15 PM
  3. Sorting ArrayList consisting of String Arrays.
    By Problemer in forum New To Java
    Replies: 2
    Last Post: 11-13-2012, 05:04 PM
  4. Replies: 1
    Last Post: 03-06-2012, 12:21 AM
  5. Replies: 1
    Last Post: 06-24-2011, 06:36 AM

Tags for this Thread

Posting Permissions

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