首页 > 解决方案 > 请我有一个公平密码,它将字符串输入转换为 Int,但我想要十六进制

问题描述

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

This is the public class
public class Process {

    private String keywordAsString = "";
    private String keyword = "";

    // ArrayList to hold the letters of the keyword with duplicates removed.
    private ArrayList<Integer> keywordAsIntsNoDup = new ArrayList<Integer>(0);

    // Map for removing all duplicate letters in the keyword.
    private Map<Integer, Integer> keywordLetters = new LinkedHashMap<Integer, Integer>(0);

    // ArrayList to hold all 256 ASCII characters (as integers).
    private ArrayList<Integer> asciiArray = new ArrayList<Integer>(0);

    // ArrayList for storing the message from the file.
    ArrayList<Integer> fileMessageAsInteger = new ArrayList<Integer>(0);

    // Constructor
    public void process() {

    }

    public void processKeyword(String keyword) {

        // Copy incoming keyword String
        this.keywordAsString = keyword;

        // Pass incoming keyword String to the removeDuplicate method.
        // removeDuplicate will first convert the letters to Integers,
        // then remove any duplicate letters.
        // Store the result in the keywordAsIntsNoDup ArrayList
        this.keywordAsIntsNoDup = removeDuplicates(this.keywordAsString);

        // Create ArrayList and fill it with all 256 ASCII characters (as integers).
        createAsciiArr();

        // Remove the keyword letters from the asciiArray. 
        for (int i=0; i<this.keywordAsIntsNoDup.size(); i++) {
            Integer letterToSearchFor = this.keywordAsIntsNoDup.get(i);
            if (this.asciiArray.contains(letterToSearchFor))
            {
                this.asciiArray.remove(letterToSearchFor);
            }
        }
    }// END processKeyword()


    public ArrayList<Integer> removeDuplicates(String keyword) {

        // Copy incoming keyword String
        this.keyword = keyword;

如果有人能帮助我,我真的很感激 Java 真的不是小菜一碟。// 循环遍历keywordAsIntArray ArrayList,将关键字的每个“字母”放入映射中。// 重复的字母将被覆盖,因此地图将包含没有任何重复的关键字。对于 (int i=0; 我

        // Put the maps' key set (which holds the 'letters') into an ArrayList.
        // This will make it easier to put the 'letters' into the Table later.
        ArrayList<Integer> keyslist = new ArrayList<Integer>(this.keywordLetters.keySet());
        System.out.println("\n" + "map.keySet() from keyslist ArrayList = " + keyslist.toString());

        return keyslist;
    }

    public void createAsciiArr() {

        // Use an enhanced for loop to fill the asciiArray ArrayList
        // with all 256 ASCII characters as integers.
        for (int i=0; i<256; i++) {
            this.asciiArray.add(i);
        }
    }// END createAsciiArr()
}// END class

请我想输入字符串作为关键字,然后取回十六进制值作为加密代码而不是整数。另外请我有更多我不太了解的代码,我对 Java 真的很陌生。请任何人都可以帮助我。

标签: stringintegerhex

解决方案


推荐阅读