MyNumber

Lisez d'abord l'énoncé, et essayez de résoudre l'exercice. Ensuite vous pouvez utiliser la boîte de sélection afin d'afficher le code correspondant.

Enoncé

La classe MyNumber nous est donnée :

  1. public class MyNumber {
  2. private static String[] digits = {
  3. "nil","one","two","three","four","five","six","seven","eight","nine","ten",
  4. "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
  5. "eighteen","nineteen","twenty"
  6. };
  7. private static String[] tens ={
  8. "twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"
  9. };
  10. private int number;
  11.  
  12. public MyNumber(int number){
  13. this.number=number;
  14. }
  15.  
  16. public String asEnglish(){
  17. //Your code here//
  18. }
  19.  
  20. }

Le but de cette classe est de retourner une chaîne de caractères qui représente la forme anglaise d'un nombre.

  • Pour simplifier le code, nous pouvons restreindre l'étendue des valeurs aux entiers entre  0 compris et 999 compris.
  • Attention au mot "and"...

Exemples :

twelve, fiftynine, two hundred and twentysix, three hundred

Contents Haut

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 15/05/2005, last modified the 08/08/2019
Source of the printed document:https://www.gaudry.be/en/javaex-rf-mynumber.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.