Results 1 to 4 of 4
Thread: incompatible types
- 01-17-2012, 02:53 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
incompatible types
import java.io.*;
public class Telegram
{
public static void main ()throws IOException
{
BufferedReader dataIn=new BufferedReader (new InputStreamReader (System.in));
double no=0, cost=0, fee=0, pay=0;
String sno= "", scost= "", sfee= "", spay= "", change= "";
System.out.println("Enter number of words: ");
sno=dataIn.readLine();
no=Double.parseDouble(sno);
System.out.println("Cost per word: ");
scost=dataIn.readLine();
cost=Double.parseDouble(scost);
fee=no*cost;
System.out.println("Total fee: "+fee);
System.out.println("Amount payed: ");
spay=dataIn.readLine();
pay=Double.parseDouble(spay);
change=pay-fee;
System.out.println("Change: "+change);
}
}
what is wrong with this? please help me.
- 01-17-2012, 03:09 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: incompatible types
Please use code tags when posting code.Java Code:import java.io.*; public class Telegram { public static void main ()throws IOException { BufferedReader dataIn=new BufferedReader (new InputStreamReader (System.in)); double no=0, cost=0, fee=0, pay=0; String sno= "", scost= "", sfee= "", spay= "", change= ""; System.out.println("Enter number of words: "); sno=dataIn.readLine(); no=Double.parseDouble(sno); System.out.println("Cost per word: "); scost=dataIn.readLine(); cost=Double.parseDouble(scost); fee=no*cost; System.out.println("Total fee: "+fee); System.out.println("Amount payed: "); spay=dataIn.readLine(); pay=Double.parseDouble(spay); [COLOR="#FFFF00"]change=pay-fee;[/COLOR] System.out.println("Change: "+change); } }
'change' is a String.
The right hand side of that assignment is a double.
You can't assign a double to a String.
Also...yellow is almost impossible to read.
- 01-17-2012, 03:14 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
Re: incompatible types
And the signature of your main() method doesn't make it the main method of your class.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-17-2012, 03:25 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
incompatible types!!
By sneha343 in forum New To JavaReplies: 7Last Post: 11-30-2011, 11:49 PM -
incompatible types
By effa in forum New To JavaReplies: 16Last Post: 02-03-2011, 09:50 AM -
Incompatible types
By bayan in forum New To JavaReplies: 5Last Post: 11-04-2010, 08:43 AM -
incompatible types error
By magic in forum New To JavaReplies: 3Last Post: 06-02-2010, 04:58 PM -
Incompatible types
By coltragon in forum New To JavaReplies: 5Last Post: 01-15-2010, 04:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks