Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= 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: 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 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