Describing code segment (newbie stuff)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Describing code segment (newbie stuff)

  1. #1
    Join Date
    Sep 2005
    Posts
    4

    Describing code segment (newbie stuff)

    A.

    Code:
    String s  = "perserverance";
    String t = s.substring(4, 6);
    String u = s.substring(3, 8);
    String v = s.substring(0, 9);
    System.out.println(t);
    System.out.println(u);
    System.out.println(v);
    This is my explaination for the above code segment:

    1. Takes the substream at the 5th character and stops at the 7th character in the string s.
    2. Takes the substream at the 4th character and stops at 9th in the string s.
    3. Takes the substream at the 1st character and stops at the 10th in the string s.

    Is that correct? Is there any step after that? What is the output of it will look like?

  2. #2
    Join Date
    Aug 2005
    Posts
    17
    Greetings,

    A few things..

    1. You accidentally wrote "substream" instead of "substring".

    2. s.substring(4,6) will get you characters 4 & 5. So you get "er". I would just say that it retrieved characters 4-5.

    So, s.substring(x,y) will get you position (x) to position (y-1)

    For more help, www.NeedProgrammingHelp.com

Similar Threads

  1. VS.Net and Code Behind
    By Chaitanya Marvici in forum ASP.NET
    Replies: 6
    Last Post: 07-21-2003, 10:15 AM
  2. Replies: 0
    Last Post: 04-11-2002, 07:48 PM
  3. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 06:40 PM
  4. TNX Rob - Re: Security of non-server code?
    By Patrick Ireland in forum .NET
    Replies: 19
    Last Post: 04-24-2001, 05:19 PM
  5. Replies: 0
    Last Post: 04-03-2001, 05:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center