Results 1 to 3 of 3
  1. #1
    hammodi is offline Member
    Join Date
    Sep 2013
    Posts
    12
    Rep Power
    0

    Default whats wrong with this simple code?

    its keeps giving me zero!

    import java.util.Scanner;


    PHP Code:
    public class FtoC {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner input= new Scanner(System.in);
    		System.out.print("Enter Temperature in Fehrenheit: ");
    		double temp=input.nextDouble();
    		System.out.println("Your temperature in Celsius is: " + ((5/9)*(temp-32))) ;
    
    	}
    
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,618
    Rep Power
    5

    Default Re: whats wrong with this simple code?

    5/9 where both 5 and 9 are ints returns 0 since ints have no fractions and it rounds down. Change to 5/9.0

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    hammodi is offline Member
    Join Date
    Sep 2013
    Posts
    12
    Rep Power
    0

    Default Re: whats wrong with this simple code?

    Quote Originally Posted by jim829 View Post
    5/9 where both 5 and 9 are ints returns 0 since ints have no fractions and it rounds down. Change to 5/9.0

    Regards,
    Jim
    yes, i keep forgetting.

    thanks!

Similar Threads

  1. Whats wrong with my jsp code?
    By ur2cdanger in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 10-28-2011, 04:16 AM
  2. whats wrong with this code?
    By Petee in forum New To Java
    Replies: 8
    Last Post: 09-30-2011, 04:39 PM
  3. Whats wrong with my code
    By zit1343 in forum New To Java
    Replies: 9
    Last Post: 01-24-2011, 01:06 AM
  4. whats wrong with this code
    By hamzeeco in forum Java Applets
    Replies: 1
    Last Post: 12-31-2010, 02:19 PM
  5. Whats wrong with my code???
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 12:54 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
  •