%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
k = (j + 13) / 27while k <= 10
k = k + 1
i = 3 * k - 1
end
上面的Ruby代码使用了while循环结构来重写伪代码段。 while循环执行重复操作直到指定的条件不再满足为止。在这个例子中,循环将执行直到k的值不再小于或等于10。
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("未找到你要删除的对象")
}
}