-
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.
-
Re: incompatible types
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);
}
}
Please use code tags when posting code.
'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.
-
Re: incompatible types
And the signature of your main() method doesn't make it the main method of your class.
kind regards,
Jos
-
Re: incompatible types
oh. thanks.. and sorry for some of those inconveniences! i'm just new here. :(nod):