LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2004, 01:48 PM   #1
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Rep: Reputation: 30
String return question


Code:
public class class1
{
   public static void main (string [] args)
{
    int i=3,j=4;
    char c[]={'a','b','c','d','e','f','g','h','i'};
    String s= new String (c,i,j);
    System.out.print(s);
}
}
why does it return
PHP Code:
defg 
?
 
Old 11-10-2004, 02:13 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
string offsets start counting at zero not one.
Code:
0 1 2 3 4 5 6 7 8 
a b c d e f g h i
 
Old 11-10-2004, 02:17 PM   #3
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Original Poster
Rep: Reputation: 30
yea but isnt it suppossed to start at 3 and return one? because i think its the value of [i - j] which would equal 1 and return character D only??
 
Old 11-10-2004, 02:46 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
the third parameter is a length, not an absolute offset, so its 3 to 3+4=7 = g.

You've asked a couple of extremely similar questions i've noticed... they read very much like homework, and not questions you are likely to come across in the course of private work... if this is the case, please do not ask these questions, as they are or you to find out and not to blindy copy an answer from LQ.

but either way you could have easily found out your answer by looking at the java api.....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash return question merchtemeagle Programming 2 11-02-2005 10:36 AM
string question AquamaN Programming 2 10-20-2005 06:17 PM
can a function return a string? hubabuba Programming 13 03-06-2005 02:51 PM
String Pointer Question (c/c++) greecesking Programming 2 08-26-2004 06:07 AM
string as return value in c raven Programming 6 02-10-2002 06:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration