Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-01-2007, 09:08 PM
Member
 
Join Date: Jun 2007
Posts: 92
Marcus is on a distinguished road
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.

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-01-2007, 09:17 PM
Member
 
Join Date: Jun 2007
Posts: 95
Felissa is on a distinguished road
I would do something like:
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-01-2007, 09:20 PM
Member
 
Join Date: Jun 2007
Posts: 95
Felissa is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Demonstration of the mathematical operators Java Tip java.util 0 04-17-2008 12:02 AM
JSP methods example Java Tip Java Tips 0 01-30-2008 11:00 AM
methods Zensai New To Java 10 12-03-2007 06:31 AM
Methods Java Tip Java Tips 0 12-01-2007 09:49 PM
Help with mathematical part in java lenny Advanced Java 3 08-09-2007 02:55 PM


All times are GMT +3. The time now is 07:09 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org