ConversionTool.java 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. public class ConversionTool {
  2. public static void main(String[] args){}
  3. public static float CentimetersToInches(float centimeters){
  4. if (centimeters <= 0){
  5. return 0;
  6. }else {
  7. return centimeters * (float)0.393701;
  8. }
  9. }
  10. public static float InchesToCentimeters(float inches){
  11. if (inches <= 0){
  12. return 0;
  13. }else {
  14. return inches * (float)2.54;
  15. }
  16. }
  17. public static float FeetToMeters(float feet){
  18. if (feet <= 0){
  19. return 0;
  20. }else {
  21. return feet * (float)0.3048;
  22. }
  23. }
  24. public static float MetersToFeet(float meters){
  25. if (meters <= 0){
  26. return 0;
  27. }else {
  28. return meters * (float)3.28084;
  29. }
  30. }
  31. public static float CelsiusToFahrenheit(float celsius){
  32. return celsius*9/5 + (float)32.0;
  33. }
  34. public static float FahrenheitToCelsius(float fahrenheit){
  35. return (fahrenheit - (float)32.0) * 5/9;
  36. }
  37. public static float MphToKph(float mph){
  38. if (mph <= 0){
  39. return 0;
  40. }else {
  41. return mph * (float)1.60934;
  42. }
  43. }
  44. public static float KphToMph(float kph){
  45. if (kph <= 0){
  46. return 0;
  47. }else {
  48. return kph * (float)0.621371;
  49. }
  50. }
  51. }