Results 1 to 1 of 1
Thread: To figure out what method does
 03142012, 10:06 PM #1Member
 Join Date
 Nov 2010
 Location
 Beirut, Lebanon
 Posts
 36
 Rep Power
 0
To figure out what method does
hello
i am currently trying to figure out what a certain method does so as to proceed to annotate it, providing a post condition and loop invariant.
what i figured out:
on a positive and negative array and all positive x becomes positive upon the first time the minimum is encountered but when the array is all negative x and y are the sum of the elements
anyone see another approach to analyzing to this method?
thank you for your time
Java Code:public class funA{ public static void functionOfA( int a[]){ int MAXINT= Integer.MAX_VALUE; int x= MAXINT; int y= MAXINT; int i= 0; int n= a.length; while( i!= n){ if( y== MAXINT){ //y= MAXINT y= a[i]; //y= a[i] x= min( x, y); //x= min(x,y) System.out.println("x: " +x + " y: "+ y); i= i+1; //y= a[i1]; } else{ y= min( y+ a[i], a[i]); // y= min( y+ a[i], a[i]); x= min( x, y); //x= min( x, y); System.out.println("x: " +x + " y: "+ y); i= i+1; // y= min( y+ a[i1], a[i1]); } } System.out.println( x+ " "+ y); } public static int min( int x, int y){ if( x< y){ return x; } else{ return y; } } public static void main ( String args[]){ int a[]= new int[] {0,9,3,2,4,3,12,3,1}; functionOfA( a); for( int i= 0; i< a.length; i++){ System.out.print( a[i]+ " "); } System.out.println(); System.out.println(); int a2[]= new int[] {9,3,10,4,2}; functionOfA( a2); for( int i2= 0; i2< a2.length; i2++){ System.out.print( a2[i2]+ " "); } } }
1. int x = MAXINT; int y = MAXINT; int i = 0;
2. int a[n];
3. while i != n {
4. y = min(y + a[i], a[i]);
5. x = min(x, y);
6. i = i + 1;
7. }Last edited by farahm; 03142012 at 10:14 PM.
Similar Threads

can someone please help me to figure this out >.<
By lyzeofkiel in forum New To JavaReplies: 11Last Post: 07242011, 12:34 PM 
Can't figure out
By beauti477 in forum New To JavaReplies: 3Last Post: 07202011, 04:58 PM 
New to Applets..How do you draw the figure in the paint method multiple times?
By etranman1 in forum Java AppletsReplies: 7Last Post: 05052011, 05:26 PM 
trying to figure out how to minus the place of an int parameter in a method.
By Dev23 in forum New To JavaReplies: 2Last Post: 04172011, 11:17 AM 
Can't figure out how to use JFrame's add() method right
By Fortu in forum New To JavaReplies: 9Last Post: 01172011, 01:14 AM
Bookmarks