亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

幫我看下為什么只能打印2門選擇課程?

package aaa;


import java.util.HashSet;

import java.util.Set;


public class student {

? ? ? ? public String id;

? ? ? ? public String name;

? ? ? ? public ? Set<coure> coures;

? ? ? ??

? ? ? ? public student(){}

? ? ? ? public student(String id,String name)

? ? ? ? {

? ? ? ? this.id=id;

? ? ? ? this.name=name;

? ? ? ? this.coures=new HashSet<coure>();

? ? ? ? }

? ? ? ??

}

package aaa;


public class coure {

public String id;

? ? ?public String name;

? ? ?public coure(){}

? ? ?public coure(String id,String name)

? ? ?{

? ? this.id=id;

? ? this.name=name;

? ? ?

? ? ?}

}

package aaa;


import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Scanner;


public class testset {

? ? public List<coure> coureselect;

? ? public testset()

? ? {

? ? this.coureselect=new ArrayList<coure>();

? ? }

? ??

? ? public void testadd()

? ? {

? ? coure c1=new coure("1", "離散數學");

? ? coureselect.add(c1);

? ?

? ? coure c2=new coure("2", "大學語文");

? ? coureselect.add(0, c2);

? ?

? ? coure[] c3={new coure("4", "物理學"),new coure("5", "生物學")};

? ? coureselect.addAll(Arrays.asList(c3));

? ?

? ? coure[] c4={new coure("6", "四級英語"),new coure("7", "計算機")};

? ? coureselect.addAll(0, Arrays.asList(c4));

? ? }

? ?

? ??

? ? public void testforeach()

? ? {

? ? for(coure cc:coureselect)

? ? {

? ? System.out.println("課程查詢:"+cc.id+" ?"+cc.name);

? ? }

? ? }

? ??

? ??

? ??

? ? public static void main(String[] args) {

testset t=new testset();

t.testadd();

t.testforeach();

student s=new student("1","小明");

System.out.println("歡迎"+s.name+"選課");

Scanner input=new Scanner(System.in);

for(int i=0;i<4;i++)

{

System.out.println("請輸入課程ID:");

String coureid=input.next();

for(coure cr:t.coureselect)

{

if(cr.id.equals(coureid))

{

s.coures.add(cr);

}

}

}

t.foreachset(s);

}

? ? public void foreachset(student s)

? ? {

? ? for(coure cr:s.coures)

? ? {

? ? System.out.println("選擇課程:"+cr.id+" "+cr.name);

? ? }

? ? }

}

無論小明選擇幾門課最后都只打印了兩門課程

正在回答

3 回答

http://img1.sycdn.imooc.com//58bbbca600011f3902410507.jpg把你的代碼運行了一下? 沒有問題?????

0 回復 有任何疑惑可以回復我~

你這里面沒有ID為3 的課程

我也不是大神? 我跟你一樣都是初學者

0 回復 有任何疑惑可以回復我~

???可是我當時運行時有問題,那我在運行試下,我又有一個問題了,我想做一個抽獎的小游戲,結果卡在第一步了,就是必須注冊成為會員才能抽獎,而原本就是會員的可以直接登錄抽獎,然后登錄這一步用戶很可能輸錯嗎,我就想用一個循環,知道賬號和密碼全對才能進行下一步,但我不知道循環該 怎么用了,原本打的代碼被我一氣之下給刪了。大神有什么意見嗎?

0 回復 有任何疑惑可以回復我~
#1

辜谷谷 提問者

為什么我運行還是有問題啊 課程查詢:6 四級英語 課程查詢:7 計算機 課程查詢:2 大學語文 課程查詢:1 離散數學 課程查詢:4 物理學 課程查詢:5 生物學 歡迎學生小明選課 請輸入課程ID 3 請輸入課程ID 4 請輸入課程ID 1 選擇課程:4物理學 選擇課程:1離散數學
2017-03-06 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

幫我看下為什么只能打印2門選擇課程?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號