Hi minhhau,

1.( if((counter == 0)||(num[counter] > max))

                max = num[counter]; )
Line 1: these lines shows that if we are strting to search for MAX number (i.e 
if counter ==0) or if the number at current position is greater then the VALUES 
stored in the MAX valriable then 
Line 2: store the value in max variable.

2. Now to change it to get the minimum number, this line will be as -

( if((counter == 0)||(num[counter] < max))

I hope these will clear you doubts.

Thanks,



Howie wrote:
> Hi all,
> I'm a bit behind on my homework here. For lab 1036, I have a few
> questions:
>
> 1. First, for this piece of code below to find the max number, can
> somebody explain to me what these two lines mean (  if((counter == 0)||
> (num[counter] > max))
>                 max = num[counter]; )
> and how do we modify it to get the minimum instead of the max ?
>
>
> import javax.swing.JOptionPane;
>
> public class GreatestNumber {
>
>     public static void main(String[] args) {
>         int[] num = new int[10];
>         int counter;
>         int max = 0;
>         int totalnumber = 3;
>
>         // Prompt a user to enter numbers
>         for(counter = 0; counter < totalnumber; counter++){
>
>             num[counter] = Integer.parseInt
>                     (JOptionPane.showInputDialog("Enter numbers until
> " + totalnumber + " numbers are entered"));
>
>             // Compute the greatest number up to this point
>             if((counter == 0)||(num[counter] > max))
>                 max = num[counter];
>         }
>
>         // Display the greatest number.
>         JOptionPane.showMessageDialog(null,"The number with the
> greatest value is " + max);
>     }
>
> }
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to