Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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 04-28-2007, 06:16 PM
Member
 
Join Date: Apr 2007
Location: Sweden
Posts: 12
Legoland is on a distinguished road
Program for calculating area and hypotenus in a triangel
Hi!
I try to make a program on this conditions:
Make a program where I can put in the values for the 2 cathetus in an right angled triangel the the program will calculate the hypotenusa and area.
I have managed the hypotenusa but are stuck on the area I get Area 0.0.
I also have probelms with the last showMeessageDialog I want the Area to be on a new line there.
The program looks like this:
import javax.swing.*;
public class Pythagoras2 {
public static void main (String[] arg) {
String s;
s = JOptionPane.showInputDialog ("First side?");
double a = Double.parseDouble(s);
s = JOptionPane.showInputDialog ("Second side?");
double b = Double.parseDouble(s);
double c = Math.sqrt(a*a + b*b);
double area = (a*b%2);
JOptionPane.showMessageDialog(null,
"Hypotenusans length: " + c + "Area:" + area);

System.exit(0);

}
}
????? I´m lost
Legoland
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-28-2007, 08:05 PM
ali ali is offline
Member
 
Join Date: Apr 2007
Posts: 7
ali is on a distinguished road
Corrections
Hi,

Try running the following code, I think it would solve all your problems

import javax.swing.*;
public class Pythagoras2 {
public static void main (String[] arg) {
String s;
s = JOptionPane.showInputDialog ("First side?");
double a = Double.parseDouble(s);
s = JOptionPane.showInputDialog ("Second side?");
double b = Double.parseDouble(s);
double c = Math.sqrt(a*a + b*b);
double area = (a*b/2);
JOptionPane.showMessageDialog(null,
"Hypotenusans length: " + c + "\nArea:" + area);

System.exit(0);

}
}

The first problem with your code was that you were trying to find the modulus (remainder) where you are supposed to divide.
You need to put in escape sequence characters to change the lines in the Message dialogs the same way that you need them when displaying the output on console.

Hope this solves the problem,

Regards
Ali
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-28-2007, 08:23 PM
Member
 
Join Date: Apr 2007
Location: Sweden
Posts: 12
Legoland is on a distinguished road
Thank you Ali!
Thanks for your help now it works fine and I understand what I missed out on.
I was totally stucked and I have noone to ask here at home.
Have a nice weekend
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-28-2007, 10:24 PM
ali ali is offline
Member
 
Join Date: Apr 2007
Posts: 7
ali is on a distinguished road
Dont mention it, I hope that you have an enjoyable weekend too.

Regards,
Ali
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-12-2008, 03:41 PM
Member
 
Join Date: Aug 2008
Posts: 11
g25451 is on a distinguished road
how are you?
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
Calculating trigonometric functions Java Tip java.lang 0 04-17-2008 12:56 AM
Calculating hyperbolic functions Java Tip java.lang 0 04-17-2008 12:55 AM
Calculating the DB connection time Java Tip Java Tips 0 01-20-2008 10:55 AM
Calculating sin of a double value Java Tip Java Tips 0 01-13-2008 10:13 PM
Print Area Riftwalker Advanced Java 0 11-28-2007 09:28 PM


All times are GMT +3. The time now is 01:22 AM.


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