我试图使用复数形式的println来表示HashSet中有多个汽车的时间,以及当它只有一个时它的单数形式。
package com.lynda.javatraining;
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
Car bmw = new Car();
Car mercedes = new Car();
Car hyundai = new Car();
HashSet<Car> set = new HashSet<>();
set.add(bmw);
if (Car == 1) {
System.out.println("there is " + set.size() + " car");
} else {
System.out.println("there are " + set.size() + " cars" );
}
}
}