随笔分类 - Lua
摘要:题目是这样的: Observe that its base and height are both equal to , and the image is drawn using # symbols and spaces. The last line is not preceded by any s
阅读全文
摘要:arr = {11, 2, 4, 4, 5, 6, 10, 8, -12} function diagonalDifference(arr) dimesion = math.sqrt(#arr) arr1 = {} sum1 = 0 arr2 = {} sum2 = 0 for i=1,dimesion do ...
阅读全文
摘要:1 --第4题 输出99乘法表 2 function PrintMulitiplyTable() 3 for i = 1, 9 do 4 local res = {} 5 local str = "" 6 for j = 1, i do 7 res[j] = i * j 8 ...
阅读全文
摘要:1 --第3题 利用循环求n的阶乘 2 --参数检查是否是自然数 3 4 function IsNaturalNumber(n) 5 if(n < 0 or n%1 ~= 0)then 6 return false 7 else 8 return true 9 end 10 end 11 function factor...
阅读全文
摘要:元表操作的一般流程 1.定义原始表 2.定义元表 3.定义元方法 4.设置元表
阅读全文
摘要:1 local array = {}; 2 local row1 = {1, 3, 5, 7, 9} 3 local row2 = {2, 4, 6, 8, 10} 4 local row3 = {"I", "love", "lua"} 5 array[1] = row1; 6 array[2] = row2; 7 array[3] = row3 8 print("length ...
阅读全文
摘要:通过代码可以得出结论: 1.ipairs函数遇到nil停止输出 2.把ipairs换成pairs 发现,输出结果是1 3 5 7 9,得出结论pairs会过滤到nil 3.select(index,...)函数的作用是返回从第i个开始的所有元素,并且会输出nil
阅读全文

浙公网安备 33010602011771号