473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Explaining a little snippet

258 100+
Hi everyone
I don't have any knowledge in JAVA.
Could anyone please explain what this JAVA class does?

What does "Double.POSITIVE_INFINITY" do?
Expand|Select|Wrap|Line Numbers
  1. public class Fraga7{
  2.     public static double min (double[] tal){
  3.         double min = Double.POSITIVE_INFINITY;
  4.         for (int i = 0; i < tal.length; i++){
  5.             if (tal[i] < min) min = tal[i];
  6.         }
  7.         return min;
  8.     }
  9. }
  10.  
Thanks
Jan 6 '13 #1

✓ answered by Anas Mosaad

The line in question (Line 3) assigns an initial min value positive infinity. It seemed weird to me but I like it.

Usually, I would set the first item of the list to min and start the loop with 1. However, I have to check if the list is empty and in that case I should return infinity. This snippet does all of this. It returns Infinity if the list is empty (i.e.
Expand|Select|Wrap|Line Numbers
  1. min(new double[]{})
). Really a very good one.

3 1299
Anas Mosaad
185 128KB
The line in question (Line 3) assigns an initial min value positive infinity. It seemed weird to me but I like it.

Usually, I would set the first item of the list to min and start the loop with 1. However, I have to check if the list is empty and in that case I should return infinity. This snippet does all of this. It returns Infinity if the list is empty (i.e.
Expand|Select|Wrap|Line Numbers
  1. min(new double[]{})
). Really a very good one.
Jan 6 '13 #2
bnashenas1984
258 100+
Thanks Anas Mosaad
I appreciate your help
Jan 6 '13 #3
Anas Mosaad
185 128KB
You are always welcome :)
Jan 6 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Arthur T. Murray | last post by:
"Bill Modlin" <modlin1@metrocast.net> wrote on Fri, 26 Sep 2003: <snip> >>> If I wanted to explain how one of my programs worked >>> I would not give someone a print out of the code. >>> First I...
11
by: alcastle | last post by:
I'm new to C. I have a snippet of code that works, but it's a little off in the output. I'm hoping someone can spot my error(s). I'm reading input from a serial device, and I need to print Hex,...
1
by: Hoopster | last post by:
Hello, I'm looking for a simple php snippet program. I have tried several and can't find exactly what I need. I'm actually looking for some sort of program where you can copy and past you php...
1
by: Gary Brown | last post by:
Hi and Happy Holidays, While typing in a member function an errant finger triggered a bit of code snippet that throws a "not yet implemented" exception if the member is called. It happened...
13
by: cougre.j | last post by:
I've got a take home final for my computer class and it has a bonus question concerning some programming that we didn't have time to cover. I've already got an A in the class, so it won't affect...
3
by: =?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno | last post by:
Could you advise me if there could be any memory leak in this C# code snippet?: http://pastebin.com/m2d2ded2d As I understand, I have closed all risky objects: EventWaitHandle, and Timer. Do...
12
by: backups2007 | last post by:
How do I submit form entries to the database and redirect to the same page, with the entries still display on the fields of the form? I really need help on this. Thanks.
1
by: martin DH | last post by:
Could anyone help explain the following snippet of code? I'm not quite sure how it works. Thanks! Public Counter As Integer Private Sub Form_Load() If Me.CurrentRecord > 0 Then ...
4
by: tshad | last post by:
I was watching a video that used a code snippet to create a property and when you type "prop" tab tab, it would create the private variable as well as the property definitions with the private...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.