javaimportant.py

Created by joelkouakou2080

Created on February 05, 2023

1.28 KB


Vous pouvez (1) importer des
bibliothèques de classes Java,
(2) créer un objet Scanner,
(3) récupérer une saisie du 
clavier, (4) formater un texte 
de sortie avec printf et 
(5) diviser et faire un modulo
sur des entiers. Maintenant,
nous allons rassembler tout ça
dans un programme complet :
  
import java.util.Scanner; 

/** 
  * Convertit les cm en pieds et pouces
  */ 
public class Convert { 
        public static void main(String[] args) { 
                    double cm; 
                    int feet, inches, remainder; 
                    final double CM_PER_INCH = 2.54; 
                    final int IN_PER_FOOT = 12; 
                    Scanner in = new Scanner(System.in); 
                    
                    // Demande à lutilisateur et récupère la valeur 
                    System.out.print("Combien de cm exactement? "); 
                    cm = in.nextDouble(); 

                    // convertit et affiche le résultat
                    inches = (int) (cm / CM_PER_INCH); 
                    feet = inches / IN_PER_FOOT; 
                    remainder = inches % IN_PER_FOOT; 
                    System.out.printf("%.2f cm = %d ft, %d in\n", 
                                                               cm, feet, remainder);
        }
 }

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.