Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38711
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: value of Math.abs(a), int a=null; |
| Date | 2019-01-22 11:20 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <q27fs5$17rp$1@gioia.aioe.org> (permalink) |
| References | <80e0e6bf-ef5a-4f3f-adf4-b5de4c6696ef@googlegroups.com> |
On 1/22/2019 11:09 AM, Akshay Goel wrote:
> In below code, how is the if statement working?
>
> Integer closest = null;
> for(int i = 0; i < n; i++) {
> int current = in.nextInt();
> if(closest == null || Math.abs(closest) > Math.abs(current)
> || Math.abs(closest) == Math.abs(current) && closest < current) closest = current;
> }
> System.out.println(closest);
|| is a short circuiting operator.
So if closest == null is true then it skip the other two OR
conditions and do closest = current..
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
value of Math.abs(a), int a=null; Akshay Goel <goelakshay001@gmail.com> - 2019-01-22 08:09 -0800 Re: value of Math.abs(a), int a=null; Arne Vajhøj <arne@vajhoej.dk> - 2019-01-22 11:20 -0500 Re: value of Math.abs(a), int a=null; Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-01-22 11:32 -0500
csiph-web