运行 ❯
获取您
自己的Java
服务器
×
更改方向
更改主题,深色/浅色
前往 Spaces
// Import the HashSet class import java.util.HashSet; public class Main { public static void main(String[] args) { // Create a HashSet object called numbers HashSet<Integer> numbers = new HashSet<Integer>(); // Add values to the set numbers.add(4); numbers.add(7); numbers.add(8); // Show which numbers between 1 and 10 are in the set for(int i = 1; i <= 10; i++) { if(numbers.contains(i)) { System.out.println(i + " was found in the set."); } else { System.out.println(i + " was not found in the set."); } } } }
在集合中未找到 1。
在集合中未找到 2。
在集合中未找到 3。
在集合中找到了 4。
在集合中未找到 5。
在集合中未找到 6。
在集合中找到了 7。
在集合中找到了 8。
在集合中未找到 9。
在集合中未找到 10。