Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class tast {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String hexa[] = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
- String binaire[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
- int i = 0;
- String carac;
- String reponse;
- do {//Boucle principale
- do {//On répète cette boucle tant que l'utilisateur n'a pas rentré une lettre figurant dans le tableau
- System.out.println("Veuillez entrer votre valeur Hexadecimal. Tapez END pour achever votre saisie. ");
- System.out.print("=> ");
- carac = sc.nextLine();
- //Boucle de recherche dans le tableau
- while(i < hexa.length && !carac.equals(hexa[i])){
- i++;
- }
- //Si i < 15 c'est que la boucle n'a pas dépassé le nombre de cases du tableau
- if (i < hexa.length){
- for(int a = 0; a < hexa.length; a++){
- hexa[a] = binaire[a];
- }
- System.out.println("À l'emplacement " + i +" du tableau nous avons = " + hexa[i]);
- }
- else //Sinon
- System.out.println( carac+ " ne se trouve pas dans le tableau !");
- }while(i >= hexa.length);
- //Tant que la saisie de l'utilisateur ne correspond pas à un therme du tableau
- do{
- System.out.println("Voulez-vous essayer à nouveau ? (O/N)");
- reponse = sc.nextLine();
- }while(!reponse.equals("N") && !reponse.equals("O"));
- }while (reponse.equals("O"));
- System.out.println("Fin du programme !");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment