Results 1 to 16 of 16
Thread: Converting Double to Int
- 05-01-2012, 03:22 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
-
Re: Converting Double to Int
Why do you think that it may convert the number?
- 05-01-2012, 04:37 AM #3
Re: Converting Double to Int
Code Conventions for the Java Programming Language: Contents
Variable names should start with a lowercase letter.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-01-2012, 01:54 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
- 05-01-2012, 01:56 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Converting Double to Int
This is me totally guessing since I am a very newbie at Java, but when I run this code:
It gives me about 4 different errors, and one of them said something (I will give an exact error in a few) about wrong type Double should be Int or something of that nature. Which left me curious if Java would auto-convert Int to DoubleJava Code:JOptionPane.showMessageDialog("The result of " + total );
- 05-01-2012, 02:27 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: Converting Double to Int
Your best bet would be to show us the full errors and the code they are occurring on.
Please do not ask for code as refusal often offends.
- 05-01-2012, 02:30 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Converting Double to Int
Here is the code I am using:
What is the best way to show the errors?Java Code:import javax.swing.JOptionPane; import java.lang.Math; public class TestThis { public static void main (String args[]) { String userInput; int oneNumber; double length; double distance; double allAround; userInput = JOptionPane.showInputDialog("Enter First Number"); oneNumber = Integer.parseInt(userInput); length = (2 * oneNumber); distance = ((2 * Math.PI) * oneNumber); allAround = (Math.PI * oneNumber); JOptionPane.showMessageDialog(Null, + "The distance is " + oneNumber ); System.exit(0); } }
- 05-01-2012, 03:07 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: Converting Double to Int
Copy and paste them into here.
Presumably these are compilation errors?Please do not ask for code as refusal often offends.
- 05-01-2012, 03:08 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: Converting Double to Int
This line:
is completely wrong, though.Java Code:JOptionPane.showMessageDialog(Null, +"The distance is " + oneNumber);
What is 'Null'?
And that first '+' is not needed.Please do not ask for code as refusal often offends.
- 05-01-2012, 03:11 PM #10
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Converting Double to Int
Nice I never knew you could copy/paste from the command prompt!! Here are the errors:
c:\A_Programs>javac j.java
j.java:19: error: possible loss of precision
circumference = (2 * Math.PI * radius);
^
required: int
found: double
j.java:21: error: possible loss of precision
area = (Math.PI * radius);
^
required: int
found: double
j.java:23: error: cannot find symbol
JOptionPane.showMessageDialog(Null, + "The circumference is " +
radius );
^
symbol: variable Null
location: class j
j.java:23: error: bad operand type String for unary operator '+'
JOptionPane.showMessageDialog(Null, + "The circumference is " +
radius );
^
4 errors
c:\A_Programs>javac TestThis.java
TestThis.java:23: error: cannot find symbol
JOptionPane.showMessageDialog(Null, + "The distance is " + oneNumber );
^
symbol: variable Null
location: class TestThis
TestThis.java:23: error: bad operand type String for unary operator '+'
JOptionPane.showMessageDialog(Null, + "The distance is " + oneNumber );
^
2 errors
- 05-01-2012, 03:59 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: Converting Double to Int
Um, that's not the code you posted above.
At least not the stuff about j.java.
And the errors for TestThis.java are both on the line I highlighted...Please do not ask for code as refusal often offends.
- 05-01-2012, 04:05 PM #12
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
- 05-01-2012, 04:05 PM #13
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
- 05-01-2012, 04:17 PM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: Converting Double to Int
Look at the API for JOptionPane and see, but as it stands that code is syntactically incorrect, before we even think about the API.
Please do not ask for code as refusal often offends.
- 05-02-2012, 02:16 PM #15
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Converting Double to Int
I am copying this code:
from this site:Java Code:JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
And when I try to run it I get an error of:
c:\A_Programs>javac tes.java
tes.java:8: error: cannot find symbol
JOptionPane.showMessageDialog(frame, "Eggs are not supposed to b
e green.");
^
symbol: variable frame
location: class tes
1 error
- 05-02-2012, 05:58 PM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Similar Threads
-
converting double to pixel coordinates
By mkj in forum New To JavaReplies: 2Last Post: 02-05-2012, 06:43 PM -
Converting double to char array?
By Blasz in forum New To JavaReplies: 9Last Post: 08-29-2010, 07:32 PM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM -
NullPointerException converting String to double
By infaddict in forum New To JavaReplies: 3Last Post: 07-19-2008, 06:01 PM -
Converting String to Double
By srini in forum New To JavaReplies: 1Last Post: 12-24-2007, 08:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks