local ItemsArry = {} for i = 1, 3 do local res = math.random(1,5) table.insert(ItemsArry, res) end local any7 = {1,2,3} -- "any7" local anyBar = {4,5} -- "anyBar" local any3 = {1,2,3,4,5} -- "any3 如果ItemsArry表中的三个数字都是 < 4 则在any7表中 如果ItemsArry表中的三个数字都是 > 4 则在anyBar表中 上面两个条件不满足则是在any3表中
时间: 2024-04-07 22:33:23 浏览: 15
根据你的要求,你可以使用Lua中的条件语句来判断ItemsArry中的数字在哪个表中出现。以下是相应的代码:
```lua
local ItemsArry = {}
for i = 1, 3 do
local res = math.random(1,5)
table.insert(ItemsArry, res)
end
local any7 = {1,2,3}
local anyBar = {4,5}
local any3 = {1,2,3,4,5}
local allLessThan4 = true
local allGreaterThan4 = true
for i = 1, 3 do
local num = ItemsArry[i]
if num >= 4 then
allLessThan4 = false
end
if num <= 4 then
allGreaterThan4 = false
end
end
if allLessThan4 then
print("ItemsArry is in any7")
elseif allGreaterThan4 then
print("ItemsArry is in anyBar")
else
print("ItemsArry is in any3")
end
```
这段代码首先生成了一个包含3个随机数字的ItemsArry数组。然后,它使用条件语句来检查ItemsArry中的数字是否满足特定条件。如果ItemsArry中的三个数字都小于4,则打印"ItemsArry is in any7";如果ItemsArry中的三个数字都大于4,则打印"ItemsArry is in anyBar";否则,打印"ItemsArry is in any3"。
请注意,这里使用了两个变量`allLessThan4`和`allGreaterThan4`来跟踪数字是否满足条件。如果你有其他要求,可以根据实际情况进行修改。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)