Re: Converting Double to Int
Why do you think that it may convert the number?
Re: Converting Double to Int
Re: Converting Double to Int
Quote:
Originally Posted by
DarrylBurke
Your right on that. I didn't mean to capitalize the "T" in total.
Re: Converting Double to Int
Quote:
Originally Posted by
Fubarable
Why do you think that it may convert the number?
This is me totally guessing since I am a very newbie at Java, but when I run this code:
Code:
JOptionPane.showMessageDialog("The result of " + total );
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 Double
Re: Converting Double to Int
Your best bet would be to show us the full errors and the code they are occurring on.
Re: Converting Double to Int
Here is the code I am using:
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);
}
}
What is the best way to show the errors?
Re: Converting Double to Int
Copy and paste them into here.
Presumably these are compilation errors?
Re: Converting Double to Int
This line:
Code:
JOptionPane.showMessageDialog(Null, +"The distance is " + oneNumber);
is completely wrong, though.
What is 'Null'?
And that first '+' is not needed.
Re: Converting Double to Int
Quote:
Originally Posted by
Tolls
Copy and paste them into here.
Presumably these are compilation errors?
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
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...
Re: Converting Double to Int
Quote:
Originally Posted by
Tolls
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...
Dangit your right, sorry I have like 3 different ones that I was trying to see if this way would work, okay what about this way. I'll check the line of code you posted above and see if I can tinker with it to get the code functioning properly.
Re: Converting Double to Int
Quote:
Originally Posted by
Tolls
This line:
Code:
JOptionPane.showMessageDialog(Null, +"The distance is " + oneNumber);
is completely wrong, though.
What is 'Null'?
And that first '+' is not needed.
Should the code just read like this:
Code:
JOptionPane.showMessageDialog("The distance is " + oneNumber);
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.
Re: Converting Double to Int
I am copying this code:
Code:
JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
from this site:
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
Re: Converting Double to Int
That's saying you don't have a 'frame' variable, so presumably you don't.