Using more than one method to find max and sum


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Using more than one method to find max and sum

  1. #1
    Join Date
    Mar 2003
    Posts
    4

    Using more than one method to find max and sum

    This is my program so far. it is giving me one error in the second method for math with the max. and i do not know what to do. and also it gave me an error that it can't resolve the "." in JOptionPane.showMessageDialog after the math method. i just didn't put it in. I appreciate any help, cause i am clueless.


    Code:
    import javax.swing.JOptionPane;
    public class program4
    {
     public static void main(String args[])
     {
    	int x;
    	int y;
    	int z;
    	
    	String one;
    	String two;
    	String three;
    	
    	one=JOptionPane.showInputDialog("Enter First Number");
    	two=JOptionPane.showInputDialog("Enter Second Number");
    	three=JOptionPane.showInputDialog("Enter third Number");
    
    	x = Integer.parseInt(one);
    	y = Integer.parseInt(two);
    	z = Integer.parseInt(one);
    	
    	}
    			public static int max(int x, int y, int z);
    			{
    			    
    	}
    				
    
    }

    I am supposed to:

    "Use a separate method for each of the following activities:
    1) calculates the sum of four integers
    2) select maximum number among four integers
    You MUST use methods other than main( ) method."

    and it is based off a program that asks you to input 4 integers, and it then calculates the sum of these 4 integers, and it selects the maximum among these four numbers. Finally, the program prints the results (the sum and the maximum) in a dialog box, each on a different line.

    thanks again

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    Next time I suggest that you post the compiler errors.

    1. Your method max() says that it returns an int, but you didn't have any return statement. It won't compile until you get it to return something (I just set it to return zero).

    2. You've got a semi-colon at the end of max that shouldn't be there. I removed it.

    Code:
    import javax.swing.JOptionPane;
    
    public class Program4
    {
            public static void main(String args[])
            {
                    int x;
                    int y;
                    int z;
    
                    String one;
                    String two;
                    String three;
    
                    one=JOptionPane.showInputDialog("Enter First Number");
                    two=JOptionPane.showInputDialog("Enter Second Number");
                    three=JOptionPane.showInputDialog("Enter third Number");
    
                    x = Integer.parseInt(one);
                    y = Integer.parseInt(two);
                    z = Integer.parseInt(one);
    
                    System.exit(0);
            }
    
            public static int max(int x, int y, int z)
            {
                    return 0;
            }
    }
    ArchAngel.
    O:-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center