Welcome to Dream.In.Code
Become a Java Expert!

Join 150,105 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,893 people online right now. Registration is fast and FREE... Join Now!




Miles to Kilometer conversion

 
Reply to this topicStart new topic

Miles to Kilometer conversion, Conversion

udiggit99
23 Jun, 2008 - 12:25 PM
Post #1

New D.I.C Head
*

Joined: 23 Jun, 2008
Posts: 11

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.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Miles To Kilometer Conversion
23 Jun, 2008 - 12:50 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

udiggit99
RE: Miles To Kilometer Conversion
23 Jun, 2008 - 01:03 PM
Post #3

New D.I.C Head
*

Joined: 23 Jun, 2008
Posts: 11

QUOTE(PsychoCoder @ 23 Jun, 2008 - 01:50 PM) *

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.



java

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

User is offlineProfile CardPM
+Quote Post

herefishyfishy
RE: Miles To Kilometer Conversion
23 Jun, 2008 - 01:27 PM
Post #4

D.I.C Head
Group Icon

Joined: 1 May, 2008
Posts: 60


Dream Kudos: 100
My Contributions
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 Jun, 2008 - 01:35 PM
User is offlineProfile CardPM
+Quote Post

fsloke
RE: Miles To Kilometer Conversion
24 Jun, 2008 - 06:42 AM
Post #5

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
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 Jun, 2008 - 05:09 PM
User is offlineProfile CardPM
+Quote Post

udiggit99
RE: Miles To Kilometer Conversion
24 Jun, 2008 - 11:30 AM
Post #6

New D.I.C Head
*

Joined: 23 Jun, 2008
Posts: 11

System.out.println("thanks");
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:53AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month