Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package learn;
- import java.util.Scanner;
- public class TPdegrés {
- public static void main(String[] args) {
- Scanner sc = new Scanner (System.in);
- double aConvertir, convertit = 0;
- char reponse = ' ', mode = ' ';
- System.out.println("CONVERTISSEUR DEGRES CELSIUS ET FAHRENHEIT");
- System.out.println("--------------------------------------------------------------------");
- do {
- do {
- mode = ' ';
- System.out.println("Choissisez le mode de conversion :");
- System.out.println("1 - Convertisseur CELSIUS - FAHRENHEIT");
- System.out.println("2 - Convertisseur FAHRENHEIT - CELSIUS");
- mode = sc.nextLine().charAt(0);
- if (mode != 1 && mode != 2)
- System.out.println("Mode inconnu");
- } while (mode != '1' && mode != '2');
- System.out.println("Veuillez saisir la température à convertir :");
- aConvertir = sc.nextDouble();
- sc.nextLine();
- if(mode == '1'){
- convertit = ((9.0/5.0) * aConvertir) + 32.0;
- System.out.print(aConvertir + " °C correspond à : ");
- System.out.println(arrondi(convertit, 2) + " °F.");
- }
- else{
- convertit = ((aConvertir - 32) * 5) / 9;
- System.out.print(aConvertir + " °F correspond à : ");
- System.out.println(arrondi(convertit, 2) + " °C.");
- }
- do {
- System.out.println("Souhaitez vous convertir une autre température ? (O/N)");
- reponse = sc.nextLine().charAt(0);
- } while (reponse != 'O' && reponse != 'N');
- } while (reponse == 'O');}
- public static double arrondi(double A, int B) {
- return (double) ( (int) (A * Math.pow(10, B) + .5)) / Math.pow(10, B);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement