Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38711

Re: value of Math.abs(a), int a=null;

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: value of Math.abs(a), int a=null;
Date Tue, 22 Jan 2019 11:20:21 -0500
Organization Aioe.org NNTP Server
Lines 19
Message-ID <q27fs5$17rp$1@gioia.aioe.org> (permalink)
References <80e0e6bf-ef5a-4f3f-adf4-b5de4c6696ef@googlegroups.com>
NNTP-Posting-Host m5eId3EBdN9hl4F1E1e76A.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0
X-Notice Filtered by postfilter v. 0.8.3
Content-Language en-US
Xref csiph.com comp.lang.java.programmer:38711

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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