Guest User

Tentative

a guest
Oct 26th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class tast {
  3.  
  4.     public static void main(String[] args) {
  5.    
  6. Scanner sc = new Scanner(System.in);       
  7.  
  8. String hexa[] = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
  9. String binaire[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  10.  
  11. int i = 0;
  12. String carac;
  13. String reponse;
  14.                  
  15. do {//Boucle principale
  16.     do {//On répète cette boucle tant que l'utilisateur n'a pas rentré une lettre figurant dans le tableau
  17.         System.out.println("Veuillez entrer votre valeur Hexadecimal. Tapez END pour achever votre saisie. ");
  18.         System.out.print("=> ");
  19.                        
  20.         carac = sc.nextLine();
  21.             //Boucle de recherche dans le tableau
  22.             while(i < hexa.length && !carac.equals(hexa[i])){
  23.               i++;
  24.             }
  25.            
  26.             //Si i < 15 c'est que la boucle n'a pas dépassé le nombre de cases du tableau
  27.             if (i < hexa.length){
  28.                for(int a = 0; a < hexa.length; a++){
  29.                hexa[a] = binaire[a];
  30.                }
  31.                
  32.                System.out.println("À l'emplacement " + i +" du tableau nous avons = " + hexa[i]);  
  33.            
  34.             }
  35.             else //Sinon
  36.               System.out.println( carac+ " ne se trouve pas dans le tableau !");
  37.                  
  38.           }while(i >= hexa.length);
  39.  
  40.           //Tant que la saisie de l'utilisateur ne correspond pas à un therme du tableau    
  41.           do{
  42.             System.out.println("Voulez-vous essayer à nouveau ? (O/N)");
  43.             reponse = sc.nextLine();
  44.           }while(!reponse.equals("N") && !reponse.equals("O"));
  45.          
  46.         }while (reponse.equals("O"));
  47.                        
  48. System.out.println("Fin du programme !");
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment