Lesson_3 作业_1 十六进制转换器

一、问题描述

  十六进制转换器:输入3A1E 转成 3B31。描述:按位置来+n ,位置从索引为0开始,超过F则从头开始

二、代码

  

 1 /********************************************
 2 //           十六进制加密
 3 //            2013-01-14
 4 ********************************************/
 5 
 6 import java.util.Scanner;
 7 
 8 public class 十六进制密码 {
 9     public static void main(String [] args){
10         System.out.println("请输入一串十六进制数:");
11         Scanner sc = new Scanner(System.in);
12         String str = sc.nextLine();
13         String [] chars = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
14         for(int i = 0; i < str.length(); i++){
15             for(int j = 0; j < 16; j++){
16                 if(chars[j].equals(str.substring(i, i+1))){
17                     System.out.print(chars[(j+i)%16]);
18                 }
19             }
20         }
21     }
22 }


三、运行结果

  

原文地址:https://www.cnblogs.com/CocoonFan/p/2861684.html