Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package learn;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TPdegrés {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner sc = new Scanner (System.in);
  10.  
  11. double aConvertir, convertit = 0;
  12. char reponse = ' ', mode = ' ';
  13.  
  14.  
  15. System.out.println("CONVERTISSEUR DEGRES CELSIUS ET FAHRENHEIT");
  16. System.out.println("--------------------------------------------------------------------");
  17.  
  18.  
  19.  
  20. do {
  21. do {
  22. mode = ' ';
  23. System.out.println("Choissisez le mode de conversion :");
  24. System.out.println("1 - Convertisseur CELSIUS - FAHRENHEIT");
  25. System.out.println("2 - Convertisseur FAHRENHEIT - CELSIUS");
  26.  
  27. mode = sc.nextLine().charAt(0);
  28. if (mode != 1 && mode != 2)
  29. System.out.println("Mode inconnu");
  30.  
  31.  
  32. } while (mode != '1' && mode != '2');
  33.  
  34. System.out.println("Veuillez saisir la température à convertir :");
  35. aConvertir = sc.nextDouble();
  36. sc.nextLine();
  37.  
  38. if(mode == '1'){
  39. convertit = ((9.0/5.0) * aConvertir) + 32.0;
  40. System.out.print(aConvertir + " °C correspond à : ");
  41. System.out.println(arrondi(convertit, 2) + " °F.");
  42. }
  43. else{
  44. convertit = ((aConvertir - 32) * 5) / 9;
  45. System.out.print(aConvertir + " °F correspond à : ");
  46. System.out.println(arrondi(convertit, 2) + " °C.");
  47. }
  48.  
  49. do {
  50.  
  51. System.out.println("Souhaitez vous convertir une autre température ? (O/N)");
  52. reponse = sc.nextLine().charAt(0);
  53. } while (reponse != 'O' && reponse != 'N');
  54.  
  55. } while (reponse == 'O');}
  56.  
  57.  
  58.  
  59. public static double arrondi(double A, int B) {
  60. return (double) ( (int) (A * Math.pow(10, B) + .5)) / Math.pow(10, B);
  61.  
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement