Results 1 to 3 of 3
  1. #1
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default Help with mathematical methods

    I have to write a a program that gives me sum(), difference(), product(), division(), remainder().

    this is what i have so far.

    Java Code:
    import javax.swing.JOptionPane;
     
     public class Ok
      {
     	public static void main (String args[])
     	 {   
     	  
     	  int result=0;
     	  int input1 =0;
     	  int input2 =0;
     	  
     	  
     	  input1=Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the first number:"));
     	  input2=Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the second number:"));
     	     
     	    
     	   result=sum(input1, input2); 
     	   
     	   
     	   JOptionPane.showMessageDialog (null, "The result is: " + result);
     	 }
     		
     	
     	public static int sum (int x, int y)
     	 {
     		return (x+y);
     	 } 
     	 
     	
     	
      }
    Thanks.

    Marcus:cool:

  2. #2
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default

    I would do something like:
    Java Code:
     result=sum(input1, input2); 
      	   
     JOptionPane.showMessageDialog (null, "The sum is: " + result);
     
     result=difference(input1, input2); 
      	   
     JOptionPane.showMessageDialog (null, "The difference is: " + result);
    Greetings

    Felissa:p

  3. #3
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default

    Well, you'll have to write the code for difference() but otherwise yes, the code should look very similar to your sum() method.

    Greetings.

    Felissa:p

Similar Threads

  1. Demonstration of the mathematical operators
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-17-2008, 12:02 AM
  2. JSP methods example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-30-2008, 11:00 AM
  3. methods
    By Zensai in forum New To Java
    Replies: 10
    Last Post: 12-03-2007, 06:31 AM
  4. Methods
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-01-2007, 09:49 PM
  5. Help with mathematical part in java
    By lenny in forum Advanced Java
    Replies: 3
    Last Post: 08-09-2007, 02:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •