Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Help with Java program calculation

  1. Dec 7, 2011 #1
    Question: Write a program to convert 22 square metres into square kilometres.
    Note: divide square metres by 1 million to produce square kilometres.
    Note also that the answer is not zero!

    I know the note says the answer is not zero but shouldn't it have some value other than 0 ?

    My code
    Code (Text):
    public class areaConverter{

    public static void main(String []args){

        long kilometrerate = 1000000;
       
        int sqmetre = 22;    
           
        double sqmtosqk;
       
        sqmtosqk = sqmetre/kilometrerate;
       
        System.out.println("The number of square Kilometres in "+sqmetre+" square meters is " + sqmtosqk);
    }
    }
     
  2. jcsd
  3. Dec 7, 2011 #2

    Hint : Declare sqmetre or kilometrerate double rather than long or int.

    You have written too many statements that were not even required.
     
  4. Dec 7, 2011 #3

    Mark44

    Staff: Mentor

    The main problems are that your program
    1) does no calculations
    2) displays an uninitialized variable, sqmtosqk
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook