for (int i = 0; i < (myArray.length - 1); i++) {
for (int j = 0; j < myArray.length - i - 1; j++) {
if (myArray[j] > myArray[j + 1]) {
char swap = myArray[j];
myArray[j] = myArray[j + 1];
myArray[j + 1] = swap;
}
}
}
它只是从数组打印输出而是打印成行。我怎么能用ruby来反映这个?
答案 0 :(得分:1)
的Python:
print ("{0:5s} {1:7s} {2:9s} {3:6s} {4:25s} {5:s}".format('Rank', 'Points', 'Comments', 'Hours', 'Sub', 'Link'))
红宝石:
puts "%-5s %-7s %-9s %-6s %-25s %-5s" % ['Rank', 'Points', 'Comments', 'Hours', 'Sub', 'Link']
可替换地:
puts sprintf("%-5s %-7s %-9s %-6s %-25s %-5s", *['Rank', 'Points', 'Comments', 'Hours', 'Sub', 'Link'])