鍵盤輸入學生人數,然后反復錄入多個學生姓名,把所有學生資訊保存到陣列中,不能重復錄入學生姓名,否則報錯并要求重新輸入。除此之外,統計不同姓的人,并輸出結果。
uj5u.com熱心網友回復:
陣列本身都是允許重復的呀!你是把所有資料結構都稱為陣列?統計這個問題,還真不是難事。給你個示例:
public class StreamTest {
private final Stream<Dish> menu = Arrays.asList(
new Dish("pork", false, 800, Dish.Type.MEAT),
new Dish("beef", false, 700, Dish.Type.MEAT),
new Dish("chicken", false, 400, Dish.Type.MEAT),
new Dish("french fries", true, 530, Dish.Type.OTHER),
new Dish("rice", true, 350, Dish.Type.OTHER),
new Dish("season fruit", true, 120, Dish.Type.OTHER),
new Dish("pizza", true, 550, Dish.Type.OTHER),
new Dish("prawns", false, 300, Dish.Type.FISH),
new Dish("salmon", false, 450, Dish.Type.FISH)
).stream();
@Test
public void testGp() {
final Map<Boolean,Long> allQueryParam = menu.collect(Collectors.groupingBy(Dish::isVegatarian, Collectors.counting()));
allQueryParam.forEach((vegatarian, total)->{
System.out.println("Dish vegatarian: "+vegatarian+", total: "+total);
});
//output:
//Dish vegatarian: false, total: 5
//Dish vegatarian: true, total: 4
}
uj5u.com熱心網友回復:
這些最好是做一個管理系統練手,放在一個main方法里面沒有多少鍛煉意義轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/177086.html
標籤:Java SE
下一篇:幫忙告訴我哪里出錯了
