Java字符(char: ‘0’-‘9’)转整型(int)

一.字符转整型

    public void charToInt() {
        for (char a = '0'; a <= '5'; a++) {
            System.out.print(a - '0');
            System.out.print(", ");
        }
        /*
        *0, 1, 2, 3, 4, 5,  */
    }

二.整型转字符(两种)

  public void intToChar1(){
        /*
        * 只能转换0-9,其他数字为字符串的转换*/
        for(int i=0;i<10;i++){
            System.out.print((char)(i+48));
            System.out.print(", ");
        }
        /*0, 1, 2, 3, 4, 5, 6, 7, 8, 9,*/
    }
   public void intToChar2(){
        for(int i=0;i<10;i++){
            System.out.print(String.valueOf(i).charAt(0));
            System.out.print(", ");
        }
        /*0, 1, 2, 3, 4, 5, 6, 7, 8, 9,*/
    }

 

0

Python 计算笛卡尔积

import itertools


class cartesian(object):
    def __init__(self):
        self._data_list = []
        self._ans = []

    def add_data(self, data=[]):  #添加生成笛卡尔积的数据列表
        self._data_list.append(data)

    def build(self):  #计算笛卡尔积
        for item in itertools.product(*self._data_list):
            self._ans.append(item)
        return self._ans
 
if __name__=="__main__":
    car=cartesian()
    car.add_data([1,2,3,4])
    car.add_data([5,6,7,8])
    car.add_data([9,10,11,12])
    car.build()

'''
(1, 5, 9)
(1, 5, 10)
......
'''

 

0