使用Ruby循环结构重写以下伪代码段?

Python013

使用Ruby循环结构重写以下伪代码段?,第1张

k = (j + 13) / 27

while 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("未找到你要删除的对象")

}

}

txt_path = File.join(File.dirname(__FILE__), "test.txt") #此处为待读取txt文件路径,可以自行设置

lines = IO.readlines(txt_path) #读取文件,保存为数组

while (puts "line number:"line_num = gets)#按Ctrl+C退出

line_num.strip!

puts lines[line_num.to_i - 1] if line_num =~ /^\d+$/ &&(1..lines.length) === line_num.to_i

end