Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default 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.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,474
    Rep Power
    21

    Default Re: incompatible types

    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);
        }
    }
    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.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,050
    Blog Entries
    7
    Rep Power
    23

    Default Re: incompatible types

    And the signature of your main() method doesn't make it the main method of your class.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  4. #4
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: incompatible types

    oh. thanks.. and sorry for some of those inconveniences! i'm just new here.

Similar Threads

  1. incompatible types!!
    By sneha343 in forum New To Java
    Replies: 7
    Last Post: 12-01-2011, 12:49 AM
  2. incompatible types
    By effa in forum New To Java
    Replies: 16
    Last Post: 02-03-2011, 10:50 AM
  3. Incompatible types
    By bayan in forum New To Java
    Replies: 5
    Last Post: 11-04-2010, 09:43 AM
  4. incompatible types error
    By magic in forum New To Java
    Replies: 3
    Last Post: 06-02-2010, 04:58 PM
  5. Incompatible types
    By coltragon in forum New To Java
    Replies: 5
    Last Post: 01-15-2010, 05:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •