Java Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.


here you can ask help for your java related problems
 
HomeLatest imagesSearchRegisterLog in

 

 find the highest value using method with array parameters

Go down 
AuthorMessage
Ak
Java Freak
Java Freak
Ak


Posts : 23
Join date : 2009-02-07

find the highest value using method with array parameters Empty
PostSubject: find the highest value using method with array parameters   find the highest value using method with array parameters EmptyMon Apr 20, 2009 4:22 am

Code:

import java.io.*;
import javax.swing.*;
public class maximumfinder
{
    int num1[] = new int[3];
    public int index;

    public void determinemax()
    {
        try
        {
            // create bufferedreader for input to command window
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
           
            //obtain user input
            System.out.println("Enter 3 values: ");
            for(index = 0; index < 3; index++)
            {
              num1[index] = Integer.parseInt(reader.readLine());
            } // end for loop
        } // end try
        catch (IOException ex)
        {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        } // end catch

        // determine the maximum value
        int result = max(num1);

        // print the max value
        JOptionPane.showMessageDialog(null, "The max value is: " + result);
    }// end method determinemax

    // returns the maximum of its 1 int array parameters
    public int max(int mnum1[])
    {
      int maxvalue = 0, offset; // initialized maxvalue to 0

      for(offset = 0; offset < 3; offset++)
      {
        // determine whether mnum1 is greater that maxvalue
        if(mnum1[offset] > maxvalue)
          maxvalue = mnum1[offset];

        // determine whether mnum1 is greater than maxvalue
        if(mnum1[offset] > maxvalue)
          maxvalue = mnum1[offset];
      }
        return maxvalue;
    }//end method max
}//end class maximumfinder

Code:

public class maxfindermain
{
    public static void main(String args[])
    {
        maximumfinder maximumfinder = new maximumfinder();
        maximumfinder.determinemax();
    }
}
Back to top Go down
https://javafreak.board-directory.net
 
find the highest value using method with array parameters
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Java Programming-
Jump to: