let's have more flexible for statement

View previous topic View next topic Go down

let's have more flexible for statement

Post by BIT0112-Rokon on Mon Aug 02, 2010 6:32 am

Guys,
Some time we need to have minimum value from an array. Lets see how to do it-

Code:

public class ForStatement {
   public static int[] myArray = { 4, 2, 9, 4, 5, 5, 6, 5, 8 };

   public static int getMinimum(int[] ints) {
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < ints.length; i++) {
         if (ints[i] < min) {
            min = ints[i];
         }
      }
      return min;
   }

   public static void main(String[] args) {
      System.out.println(getMinimum(myArray));
   }
}


now let make our for statement more flexible to use..

Code:

public static int getMinimum(int[] ints) {
      int minimum = Integer.MAX_VALUE;
      for (int x : ints) {
         if (x < minimum) {
            minimum = x;
         }
      }
      return minimum;
   }

I think, second for statement is more flexible.
what do you think?


Last edited by BIT0112-Rokon on Sun Aug 14, 2011 1:40 am; edited 1 time in total

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: let's have more flexible for statement

Post by BIT0125-Tauhid on Mon Aug 02, 2010 7:47 am

hmm....moja to....

_________________________________________________________________
নারীর অস্তিত্ব যদি হয় সতিত্ব রক্ষা,
তবে বিয়ে করার দরকার কি ???
avatar
BIT0125-Tauhid
Club Moderator
Club Moderator

Posts : 113
Points : 176

View user profile

Back to top Go down

Re: let's have more flexible for statement

Post by BIT0112-Rokon on Mon Aug 02, 2010 8:19 am

I've decided to write some tips everyday... hope you guys will enjoy....

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: let's have more flexible for statement

Post by BIT0125-Tauhid on Tue Aug 03, 2010 5:12 am

where is tips of today????

_________________________________________________________________
নারীর অস্তিত্ব যদি হয় সতিত্ব রক্ষা,
তবে বিয়ে করার দরকার কি ???
avatar
BIT0125-Tauhid
Club Moderator
Club Moderator

Posts : 113
Points : 176

View user profile

Back to top Go down

Re: let's have more flexible for statement

Post by BIT0112-Rokon on Tue Aug 03, 2010 5:23 am

will be available soon ... dont worry...

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: let's have more flexible for statement

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum