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


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

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

X-Received by 2002:ac8:292a:: with SMTP id y39mr1208443qty.4.1548173381044; Tue, 22 Jan 2019 08:09:41 -0800 (PST)
X-Received by 2002:a25:2e04:: with SMTP id u4mr20282ybu.2.1548173380801; Tue, 22 Jan 2019 08:09:40 -0800 (PST)
Path csiph.com!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer04.fr7!futter-mich.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!v55no10696040qtk.0!news-out.google.com!m21ni6884qta.0!nntp.google.com!v55no10696038qtk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.programmer
Date Tue, 22 Jan 2019 08:09:40 -0800 (PST)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=103.217.135.100; posting-account=7Nv6cgoAAACorPcue4UZnDMQpZkaUt_F
NNTP-Posting-Host 103.217.135.100
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <80e0e6bf-ef5a-4f3f-adf4-b5de4c6696ef@googlegroups.com> (permalink)
Subject value of Math.abs(a), int a=null;
From Akshay Goel <goelakshay001@gmail.com>
Injection-Date Tue, 22 Jan 2019 16:09:41 +0000
Content-Type text/plain; charset="UTF-8"
X-Received-Bytes 1502
X-Received-Body-CRC 1358760920
Xref csiph.com comp.lang.java.programmer:38710

Show key headers only | View raw


Hi all,

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);

Back to comp.lang.java.programmer | Previous | NextNext 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