Ruby
xxxxxxxxxx
require 'set'
Vegetable=Set.new(["potato","brocolli","broccoflower","lentils","peas","fennel","chilli","cabbage"])
puts "Enter the element:-"
element = gets.chomp
val = Vegetable === element
if val == true
puts "#{element} is Present in the set."
else
puts "#{element} is not Present in the set."
end
Enter the element:- tomato tomato is not Present in the set.
示例 2
Ruby
xxxxxxxxxx
require 'set'
Vegetable=Set.new(["potato","brocolli","broccoflower","lentils","peas","fennel","chilli","cabbage"])
puts "Enter the element:-"
element = gets.chomp
val1 = false
Vegetable.each do |string|
if string == element
val1 = true
end
end
if val1 == true
puts "#{element} is present in the set."
else
puts "#{element} is not present in the set."
end
Enter the element:- tomato tomato is not Present in the set.
Linux - 如何安装 anc-api-tools
Linux - 如何安装 curvedns
Linux - 如何安装 zenmap
Python - 检查数字是正数、负数还是 0
C - 计算整数中的位数
C++ - 检查一个数字是否是素数
C - 使用动态内存分配查找最大数
C++ - 检查闰年
JavaScript - 检查字符串是否以某些字符开头和结尾
Kotlin - 反转数字
Linux - 如何安装 zstd
C++ - 求商和余数
Python - 编写 Excel (XLSX) 文件
Linux - 如何安装 xbitmaps
Kotlin - 查找数字的阶乘
Kotlin - 将数字四舍五入到 n 个小数位
Java - 反转数字
Java - 创建金字塔和图案
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month