Results 1 to 2 of 2
Thread: Program that truncates a number
- 03-25-2011, 09:27 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
Program that truncates a number
Hi am i new to java and i am trying to write this basic program with methods however it will not work and i am not sure why. and suggestions would be great thanks.
A screenshot of the program/errors are here.
Pictures by scottmulla - Photobucket
-
it is very difficult to follow code from a picture, especially a low resolution picture, so it would be appreciated if you would copy + paste the code here wrapped in [code] /code tags next time. anyhow, from the screenshot i did notice the error message you got:
"java.lang.String cannot be applied to java.lang.Double"
when you get any message like that it means you made a type-mismatch, which happens when the java compiler is expecting a variable to be of a certain type i.e. Double but it is fed with another type i.e. String.
as an example, you cannot do the following:
Java Code:String today = "25"; Double tomorrow = today + 1;
without first converting the String in question to a Double like this:
Java Code:Double tomorrow = Double.parseDouble(today) + 1;
the same works the other way around too, you cannot do the following:
Java Code:System.out.println(tomorrow);
because the function "println" only takes the type String, so you must first convert the double "tomorrow" back to a string like this:
Java Code:System.out.println(Double.toString(tomorrow));
hope this helps..Last edited by ozzyman; 03-25-2011 at 09:49 PM.
Similar Threads
-
smallest number java program
By elmo in forum New To JavaReplies: 9Last Post: 11-18-2010, 09:29 PM -
Program to read integers until a specific number?
By equal in forum New To JavaReplies: 5Last Post: 11-17-2010, 05:53 PM -
Phone number Program ..
By Sary in forum New To JavaReplies: 9Last Post: 03-17-2010, 07:15 PM -
A Number Converting Program!
By WastedxYears in forum New To JavaReplies: 2Last Post: 01-09-2010, 12:47 AM -
how to right a program that find kth number in two sorted array?
By fireball2008 in forum New To JavaReplies: 8Last Post: 04-22-2008, 03:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks