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.
Miles to Kilometer conversionConversion
Page 1 of 1
5 Replies - 44007 Views - Last Post: 24 June 2008 - 12:30 PM
Replies To: Miles to Kilometer conversion
#3
Re: Miles to Kilometer conversion
Posted 23 June 2008 - 02:03 PM
PsychoCoder, 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.");
}
}
#4
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.
P.S. We call it a method, not a function.
This post has been edited by herefishyfishy: 23 June 2008 - 02:35 PM
#5
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....
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
#6
Re: Miles to Kilometer conversion
Posted 24 June 2008 - 12:30 PM
System.out.println("thanks");
Page 1 of 1

New Topic/Question
Reply



MultiQuote


|