5 Replies - 44007 Views - Last Post: 24 June 2008 - 12:30 PM Rate Topic: -----

#1 udiggit99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-June 08

Miles to Kilometer conversion

Posted 23 June 2008 - 01:25 PM

could someone help me with a simple conversion program for my intro to java class.
I need it to to convert miles to kilometers. with a scanner function.
Is This A Good Question/Topic? 0
  • +

Replies To: Miles to Kilometer conversion

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Miles to Kilometer conversion

Posted 23 June 2008 - 01:50 PM

[rules][/rules]

Was This Post Helpful? 0
  • +
  • -

#3 udiggit99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-June 08

Re: Miles to Kilometer conversion

Posted 23 June 2008 - 02:03 PM

View PostPsychoCoder, on 23 Jun, 2008 - 01:50 PM, said:

[rules][/rules]



import java.io.*;
import java.util.*;

class MilesToKms{
  public static void main (String[] args)throws Exception{
    //1 mile = 1.609 344 kilometer;
    int miles
    Scanner  scan= new Scanner (System.in);
    System.out.print("Enter a number of miles: ");
    float km = miles * 1.609344f;
    System.out.println(miles + " miles is " + km + " kilometers.");
  }
}


Was This Post Helpful? 0
  • +
  • -

#4 herefishyfishy   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 60
  • Joined: 01-May 08

Re: Miles to Kilometer conversion

Posted 23 June 2008 - 02:27 PM

You're missing a semicolon. Also, the value of miles will be 0 because it was not assigned another value; simply creating a Scanner will not change the value of miles. You have to say: miles=scan.nextInt(); And don't forget to put scan.close(); at the end of the program.

P.S. We call it a method, not a function.

This post has been edited by herefishyfishy: 23 June 2008 - 02:35 PM

Was This Post Helpful? 0
  • +
  • -

#5 fsloke   User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 413
  • Joined: 19-December 07

Re: Miles to Kilometer conversion

Posted 24 June 2008 - 07:42 AM

Use NetBean or elipse for the IDE...

Don't type code without IDE

Pls install JDK first before install IDE

P/S IDE mean Debugger

miles=scan.nextInt();
scan.nextDouble()........ When you dot you will see the option....

This post has been edited by fsloke: 24 June 2008 - 06:09 PM

Was This Post Helpful? 0
  • +
  • -

#6 udiggit99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-June 08

Re: Miles to Kilometer conversion

Posted 24 June 2008 - 12:30 PM

System.out.println("thanks");
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1