import java.util.Scanner;
public class PracticeQuestionWK4 {
private static double computeDifference(double first, double second) {
if (first <= second) {
System.out.println("First double must be greater than second double, please try again.");
} else {
System.out.println(first - second);
}
return first - second;
}
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
System.out.print("Enter first double: ");
double firstDouble = myScanner.nextDouble();
System.out.print("Enter second double: ");
double secondDouble = myScanner.nextDouble();
computeDifference(firstDouble, secondDouble);
}
}
This code feels awkward. Is there a purpose using private static double instead of private static void here? The question I'm answering calls for a return but it seems redundant. What should I do?
Aucun commentaire:
Enregistrer un commentaire