Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Your good nature will bring unbounded happiness.


devel / comp.lang.java.programmer / how do you determine whether to start at 0 or 1 ?

SubjectAuthor
* how do you determine whether to start at 0 or 1 ?karen goh
`* how do you determine whether to start at 0 or 1 ?Andreas Leitgeb
 `- how do you determine whether to start at 0 or 1 ?e.d.pro...@gmail.com

1
how do you determine whether to start at 0 or 1 ?

<f79712ee-8e36-44e6-97dd-00b271558671n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=470&group=comp.lang.java.programmer#470

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a0c:9a4e:0:b0:4b1:d537:c6b9 with SMTP id q14-20020a0c9a4e000000b004b1d537c6b9mr12223345qvd.3.1666283742009;
Thu, 20 Oct 2022 09:35:42 -0700 (PDT)
X-Received: by 2002:a05:6870:a7a4:b0:136:7c39:979e with SMTP id
x36-20020a056870a7a400b001367c39979emr9270794oao.96.1666283741601; Thu, 20
Oct 2022 09:35:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Thu, 20 Oct 2022 09:35:41 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=121.7.234.148; posting-account=X2-SgwoAAAAps3VXHKvpx3x1f5J7nIt3
NNTP-Posting-Host: 121.7.234.148
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f79712ee-8e36-44e6-97dd-00b271558671n@googlegroups.com>
Subject: how do you determine whether to start at 0 or 1 ?
From: contact@hi5tutors.com (karen goh)
Injection-Date: Thu, 20 Oct 2022 16:35:42 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1448
 by: karen goh - Thu, 20 Oct 2022 16:35 UTC

Hi,

I have problem in determining to start at 0 or 1 when doing LeetCode DSA questions.

And also whether to use arrays.length -1 that kind of things as well as using 2 loops to do the sorting and whether to start the 2nd loop at 0 or 1 and sometimes people use the second loop to start at the first loop 0 index.

Till now because of this, I can't really confidently do DSA test.

Hope someone can give me some guidance.

Tks.

Re: how do you determine whether to start at 0 or 1 ?

<slrntm7vog.1qde.avl@logic.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=473&group=comp.lang.java.programmer#473

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.java.programmer
Subject: Re: how do you determine whether to start at 0 or 1 ?
Date: Thu, 3 Nov 2022 17:49:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <slrntm7vog.1qde.avl@logic.at>
References: <f79712ee-8e36-44e6-97dd-00b271558671n@googlegroups.com>
Reply-To: avl@logic.at
Injection-Date: Thu, 3 Nov 2022 17:49:04 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="824b9e953c48755bbdc4a584a2bda47e";
logging-data="1597125"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/obtgSRF/zQ8UBpeXEU++T"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:2JFb3afXQbf0BoeaA2GIexJFpZQ=
 by: Andreas Leitgeb - Thu, 3 Nov 2022 17:49 UTC

karen goh <contact@hi5tutors.com> wrote:
> Hi,
> I have problem in determining to start at 0 or 1 when doing LeetCode DSA questions.
> And also whether to use arrays.length -1 that kind of things as well as using 2 loops
> to do the sorting and whether to start the 2nd loop at 0 or 1 and sometimes people
> use the second loop to start at the first loop 0 index.

Java starts indexing with 0, so for an array like:
int arr[] = new int[1];
you'd use index 0 for the one and only element, and arr.length would be 1.

A typical loop with an index would (in Java) look like:
for (int i=0; i<arr.length; i++) {
... do something with arr[i]...;
}
although there's also:
for (int a : arr) {
... do something with a...;
}
if you only need the values, but not their respective index.

I have no idea what you mean by "LeetCode DSA", and if they have
anything to do with Java, so I don't know, what index they feel like
having for the first element of their arrays.

> Hope someone can give me some guidance.
> Tks.

Re: how do you determine whether to start at 0 or 1 ?

<7276c6f6-4231-4602-9a36-7d84688400a5n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=475&group=comp.lang.java.programmer#475

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a0c:e2d4:0:b0:4bb:5902:922c with SMTP id t20-20020a0ce2d4000000b004bb5902922cmr28344138qvl.57.1667505123445;
Thu, 03 Nov 2022 12:52:03 -0700 (PDT)
X-Received: by 2002:a9d:174:0:b0:66c:2b73:4183 with SMTP id
107-20020a9d0174000000b0066c2b734183mr16155456otu.8.1667505123152; Thu, 03
Nov 2022 12:52:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Thu, 3 Nov 2022 12:52:02 -0700 (PDT)
In-Reply-To: <slrntm7vog.1qde.avl@logic.at>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <f79712ee-8e36-44e6-97dd-00b271558671n@googlegroups.com> <slrntm7vog.1qde.avl@logic.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7276c6f6-4231-4602-9a36-7d84688400a5n@googlegroups.com>
Subject: Re: how do you determine whether to start at 0 or 1 ?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Thu, 03 Nov 2022 19:52:03 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1782
 by: e.d.pro...@gmail.com - Thu, 3 Nov 2022 19:52 UTC

> I have no idea what you mean by "LeetCode DSA", and if they have
> anything to do with Java, so I don't know, what index they feel like
> having for the first element of their arrays.
> > Hope someone can give me some guidance.
> > Tks.

Apparently LeetCode is a code training web site and DSA is a test they offer for data structures and algorithms.
The basic array[] variables are all zero based. Some utility object classes are one based.
Indexes for instance in java.sql.PreparedStatement are one based.
When it comes to objects, if there's any question, the answer should be in the javadocs.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor