Ruby字节数组转换为十六进制字符串

Python07

Ruby字节数组转换为十六进制字符串,第1张

str = "Ruby"

str.split(//).each {|e|print (e.unpack('H*').to_s + "\n")}

#irb

# 52

# 75

# 62

# 79

# =>["R", "u", "b", "y"]

public static void main(String[] args)

{

int [] num =new int[]{1,2,3,4,5,6,7,8,9,10}

Scanner input = new Scanner(System.in)

int temp=0

System.out.println("请输入你要删除的元素:")

int de=input.nextInt()

for(int i =0i<num.lengthi++)

{

if(num[i]==de)

{

for(int j = ij<num.length-1j++)

{

num[j]=num[j+1]

}

temp=1

break

}

}

if(temp==1)

{

System.out.println("删除此对象后数组值为:")

for(int i = 0i<num.length-1i++)

{

System.out.print(num[i]+"\t")

}

}

else

{

System.out.println("未找到你要删除的对象")

}

}

得到不同数据的值:

%w(a b c a c d).uniq

得到各个元素出现的个数:

count_hash = {}

%w(a b c a c d).each do |item|

key = item.to_sym

if count = count_hash[key]

count_hash[key] = count + 1

else

count_hash[key] = 1

end

end