Хорошо, поэтому в этой программе довольно много проблем. Код должен выглядеть примерно так:
import java.util.Scanner;
public class ConvertF {
public static void main(String args[]){
Scanner s = new Scanner(System.in);
System.out.println("How many feet do you wish to convert to miles?");
//Grab the user's input and store in feet input
int feetInput = s.nextInt();
System.out.println("Passing values to ConverToMiles");
//Store the value returned by convertToMiles in milesOutput
double milesOutput = convertToMiles(feetInput);
//This prints the output - note how I have used "%2.2f" as we are now working
//with floats (or more precisely doubles)
System.out.printf(feetInput + " feet equals %2.2f miles", milesOutput);
}
/*
* The word after static is the type the method returns (in this case a double)
* the parameter (int feet) has local scope to this method. This means that
* only this method can see the variable 'feet' - basically you cannot use feet
* in the main method above. You are not required to declare a 'miles' variable as
* this is the value the method is returning, it can be stored in a variable where
* the method is called
*/
public static double convertToMiles(int feet){
return feet/5280.0; //One of these values must be a double to return a double
}
}
Пожалуйста, прочитайте комментарии, чтобы лучше понять, как все работает.
Также обратите внимание, как я изменил ваш метод на convertToMiles
вместо ConvertToMiles
. Это всего лишь соглашение Java, которое помогает сделать ваш код легче для чтения, особенно когда он увеличивается в размере.
Надеюсь, это поможет, и счастливого кодирования:)