Задача Inches to Centimeters
Може ли да ми кажете каква е разликата между двата кода, защото на единия ми дава 50%, а на другия 100?
50%
import java.util.Scanner;
public class otherExercise {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("inches= ");
double inches = console.nextInt();
double centimeters = 2.54 * inches;
System.out.println("centimeters = " + centimeters );
}
}
100 %
import java.util.Scanner;
public class otherExercise {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("inches= ");
double inches = Double.parseDouble(console.nextLine());
double centimeters = 2.54 * inches;
System.out.println("centimeters = " + centimeters );
}
}