第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

關(guān)于已知學(xué)生名字,修改其ID。希望大神可以指點我一下。。。

import?java.util.Collection;
import?java.util.HashMap;
import?java.util.Map;
import?java.util.Map.Entry;
import?java.util.Scanner;
import?java.util.Set;

public?class?MapTest?{
	public?Map<String,?Student>?student;
	Scanner?input?=?new?Scanner(System.in);

	public?MapTest()?{
		student?=?new?HashMap<String,?Student>();
	}
	public?static?void?main(String[]?args)?{
		MapTest?mapTest=new?MapTest();
		mapTest.mapAddStu();
		mapTest.modifyStu();
	}
	public?void?mapAddStu()?{
		String?choice?=?"t";
		String?str1,str2;
		while?(choice.equalsIgnoreCase("t"))?{
			System.out.println("請輸入要添加學(xué)生的學(xué)生的ID:");
			str1?=?input.next();
			if?(student.get(str1)?==?null)?{
				System.out.println("請輸入學(xué)生姓名:");
				str2?=?input.next();
				Student?stu?=?new?Student(str1,?str2);
				student.put(str1,?stu);
				System.out.println("添加成功!\n還要繼續(xù)添加嗎?(t/f):");
				choice?=?input.next();
			}?else?{
				System.out.println("您輸入的ID已占用,請重新輸入!");
				continue;
			}
			
		}
		System.out.println("添加了一下學(xué)生:");
		printStu();
	}
	public?void?modifyStu(){
		String?str1,str2,choice="t";
//		while(choice.equalsIgnoreCase("t")){
//		System.out.println("請輸入要修改的學(xué)生ID:");
//		??str1=input.next();
//		if(student.containsKey(str1)){
//			System.out.println("請輸入學(xué)生姓名:");
//			??str2=input.next();
//			Student?stu1=new?Student(str1,str2);
//			student.put(str1,?stu1);
//			System.out.println("還要繼續(xù)修改嗎?");
//			choice=input.next();
//			}else?{
//				System.out.println("您輸入的ID不存在!");
//				continue;
//			}
//		??
//		}	
		choice="t";
	????int?i=0;
		while(choice.equalsIgnoreCase("t")){
			System.out.println("請輸入要修改的學(xué)生名字:");
			str2=input.next();
			Collection<Student>?stu=student.values();
			for(Student?s:stu){
				if(str2.equals(s.getName())){
					System.out.println("請輸入要修改的ID:");
					str1=input.next();
					//????????????????
					i=1;
					System.out.println("還要繼續(xù)修改嗎?");
					choice=input.next();
					break;
				}
			}
			if(i==0){
				System.out.println("您輸入的學(xué)生名字不存在!");
				continue;
			}
		}
		printStu();
	}
	public?void?printStu(){
		Set<Entry<String,?Student>>?stu=student.entrySet();
		for(Entry<String,?Student>?s:stu){
			System.out.println("學(xué)生ID:"+s.getKey()+"?學(xué)生名字:"+(s.getValue()).getName());
		}
	}
	
}

問號那里改填什么?

正在回答

8 回答

? ? ? ? while(choice.equalsIgnoreCase("t")){

? ? ? ? ? ? System.out.println("請輸入要修改的學(xué)生名字:");

? ? ? ? ? ? str2=input.next();

? ? ? ? ? ? Collection<Student> stu=student.values();

? ? ? ? ? ? for(Student s:stu){

? ? ? ? ? ? ? ? if(str2.equals(s.Name)){

? ? ? ? ? ? ? ? ? ? System.out.println("請輸入要修改的ID:");

? ? ? ? ? ? ? ? ? ? str1=input.next();

? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? ? ? System.out.println("還要繼續(xù)修改嗎?");

? ? ? ? ? ? ? ? ? ? choice=input.next();

? ? ? ? ? ? ? ? ? ? i = 1;

? ? ? ? ? ? ? ? ? ? if (choice.equals("f")) {

? ? ? ? ? ? ? ? ? ? student.put("1", new Student(str1, str2));

? ? ? ? ? ? ? ? ? ? break;

}

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? if(i==0){

? ? ? ? ? ? ? ? System.out.println("您輸入的學(xué)生名字不存在!");

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? }


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

如果繁星能來到我身邊 提問者

...你并沒有寫出來
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~
#2

如果繁星能來到我身邊 提問者

看錯了不好意思。謝謝你??!~~
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~
#3

如果繁星能來到我身邊 提問者

非常感謝!
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~


這是全部的代碼,你那個printStu中的s.getKey()是得到的類似于數(shù)組下標(biāo)的東西,只有得到下標(biāo)對應(yīng)元素的ID才是學(xué)生的ID,那會改了忘了貼出來了

圖片是更改后的http://img1.sycdn.imooc.com//5731d7490001091119201080.jpg測試

---------我也改了為私有類型的------------

private String Id;

private String Name;


public Student(String Id, String Name){

this.Id = Id;

this.Name = Name;

this.courses = new HashSet();

}


public String getId(){

return this.Id;

}

public void setId(String ID){

this.Id = ID;

}

public void setName(String name){

this.Name = name;

}

public String getName(){

return this.Name;

}

---------你再對照看看下面的--------

package collection;

import java.util.Collection;

import java.util.HashMap;

import java.util.Map;

import java.util.Map.Entry;

import java.util.Scanner;

import java.util.Set;

?

public class test {

? ? public Map<String, Student> student;

? ? Scanner input = new Scanner(System.in);

?

? ? public test() {

? ? ? ? student = new HashMap<String, Student>();

? ? }

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

? ? ? ? test mapTest=new test();

? ? ? ? mapTest.mapAddStu();

? ? ? ? mapTest.modifyStu();

? ? }

? ? public void mapAddStu() {

? ? ? ? String choice = "t";

? ? ? ? String str1,str2;

? ? ? ? while (choice.equalsIgnoreCase("t")) {

? ? ? ? ? ? System.out.println("請輸入要添加學(xué)生的學(xué)生的ID:");

? ? ? ? ? ? str1 = input.next();

? ? ? ? ? ? if (student.get(str1) == null) {

? ? ? ? ? ? ? ? System.out.println("請輸入學(xué)生姓名:");

? ? ? ? ? ? ? ? str2 = input.next();

? ? ? ? ? ? ? ? Student stu = new Student(str1, str2);

? ? ? ? ? ? ? ? student.put(str1, stu);

? ? ? ? ? ? ? ? System.out.println("添加成功!\n還要繼續(xù)添加嗎?(t/f):");

? ? ? ? ? ? ? ? choice = input.next();

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? System.out.println("您輸入的ID已占用,請重新輸入!");

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? ? ? ?

? ? ? ? }

? ? ? ? System.out.println("添加了一下學(xué)生:");

? ? ? ? printStu();

? ? }

? ? public void modifyStu(){

? ? ? ? String str1,str2,choice="t";

// ? ? ?while(choice.equalsIgnoreCase("t")){

// ? ? ?System.out.println("請輸入要修改的學(xué)生ID:");

// ? ? ? ?str1=input.next();

// ? ? ?if(student.containsKey(str1)){

// ? ? ? ? ?System.out.println("請輸入學(xué)生姓名:");

// ? ? ? ? ? ?str2=input.next();

// ? ? ? ? ?Student stu1=new Student(str1,str2);

// ? ? ? ? ?student.put(str1, stu1);

// ? ? ? ? ?System.out.println("還要繼續(xù)修改嗎?");

// ? ? ? ? ?choice=input.next();

// ? ? ? ? ?}else {

// ? ? ? ? ? ? ?System.out.println("您輸入的ID不存在!");

// ? ? ? ? ? ? ?continue;

// ? ? ? ? ?}

// ? ? ? ?

// ? ? ?} ?

? ? ? ? choice="t";

? ? ? ? int i=0;

? ? ? ? while(choice.equalsIgnoreCase("t")){

? ? ? ? ? ? System.out.println("請輸入要修改的學(xué)生名字:");

? ? ? ? ? ? str2=input.next();

? ? ? ? ? ? Collection<Student> stu=student.values();

? ? ? ? ? ? for(Student s:stu){

? ? ? ? ? ? ? ? if(str2.equals(s.getName())){

? ? ? ? ? ? ? ? ? ? System.out.println("請輸入要修改的ID:");

? ? ? ? ? ? ? ? ? ? str1=input.next();

? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? ? ? System.out.println("還要繼續(xù)修改嗎?");

? ? ? ? ? ? ? ? ? ? choice=input.next();

? ? ? ? ? ? ? ? ? ? i = 1;

? ? ? ? ? ? ? ? ? ? if (choice.equals("f")) {

? ? ? ? ? ? ? ? ? ? student.put(s.getId(), new Student(str1, str2));

? ? ? ? ? ? ? ? ? ? break;

}

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? if(i==0){

? ? ? ? ? ? ? ? System.out.println("您輸入的學(xué)生名字不存在!");

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? printStu();

? ? }

? ? public void printStu(){

? ? ? ? Set<Entry<String, Student>> stu=student.entrySet();

? ? ? ? for(Entry<String, Student> s:stu){

? ? ? ? ? ? System.out.println("學(xué)生ID:"+s.getValue().getId()+" 學(xué)生名字:"+(s.getValue()).getName());

? ? ? ? }

? ? }

? ? ?

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

http://img1.sycdn.imooc.com//5731d43e0001835e03150518.jpg

這是iterator,和for語句的輸出結(jié)果。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

擁抱每天最早的陽光

你獲取的都是Map映射中的下標(biāo),不是那個位置的學(xué)生的ID
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~
#2

如果繁星能來到我身邊 提問者 回復(fù) 擁抱每天最早的陽光

總算明白了,謝謝大神解惑!
2016-05-11 回復(fù) 有任何疑惑可以回復(fù)我~
??while(choice.equalsIgnoreCase("t")){
????????????System.out.println("請輸入要修改的學(xué)生名字:");
????????????str2=input.next();
????????????Collection<Student>?stu=student.values();
????????????for(Student?s:stu){
????????????????if(str2.equals(s.getName())){
????????????????????System.out.println("請輸入要修改的ID:");
????????????????????str1=input.next();
????????????????????
????????????????????System.out.println("還要繼續(xù)修改嗎?");
????????????????????choice=input.next();
????????????????????i?=?1;
????????????????????if?(choice.equals("f"))?{
????????????????????student.put(s.getId(),?new?Student(str1,?str2));
????????????????????System.out.println("修改成功");
????????????????????break;
}
???????????????????
????????????????}
????????????}
????????????if(i==0){
????????????????System.out.println("您輸入的學(xué)生名字不存在!");
????????????????continue;
????????????}
????????????printStu();
????????}
????????public?void?printStu(){
		Set<Entry<String,?Student>>?stu=student.entrySet();
		Iterator<Entry<String,?Student>>?it=stu.iterator();
		while(it.hasNext()){
			Entry?c=(Entry)?it.next();
			System.out.println(((Student)c.getValue()).getId()
					+"?"+((Student)c.getValue()).getName());
		}
//		for(Entry<String,?Student>?s:stu){
//			System.out.println("學(xué)生ID:"+s.getKey()+"?學(xué)生名字:"+(s.getValue()).getName());
//		}
}

原來是printStu出了問題。。。。但是為什么注釋掉的for語句只能打印輸出原來沒修改的呢?

0 回復(fù) 有任何疑惑可以回復(fù)我~

http://img1.sycdn.imooc.com//5731c02a0001d55602850364.jpg

奇怪的是,我的getid()方法在這個循環(huán)就不能用了,但是

public?static?void?main(String[]?args)?{
MapTest?mapTest=new?MapTest();
//mapTest.mapAddStu();
//mapTest.modifyStu();
Student?stu1=new?Student("a","s");
System.out.println(stu1.getId());
}

就可以得到id,是什么原因呢?

0 回復(fù) 有任何疑惑可以回復(fù)我~

http://img1.sycdn.imooc.com//5731bbfd0001ff3c07190387.jpg

因為我的學(xué)生類,ID設(shè)為private的,所以用的get方法。。

http://img1.sycdn.imooc.com//5731bc470001147503090389.jpg

0 回復(fù) 有任何疑惑可以回復(fù)我~

? ? ? ? while(choice.equalsIgnoreCase("t")){

? ? ? ? ? ? System.out.println("請輸入要修改的學(xué)生名字:");

? ? ? ? ? ? str2=input.next();

? ? ? ? ? ? Collection<Student> stu=student.values();

? ? ? ? ? ? for(Student s:stu){

? ? ? ? ? ? ? ? if(str2.equals(s.Name)){

? ? ? ? ? ? ? ? ? ? System.out.println("請輸入要修改的ID:");

? ? ? ? ? ? ? ? ? ? str1=input.next();

? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? ? ? System.out.println("還要繼續(xù)修改嗎?");

? ? ? ? ? ? ? ? ? ? choice=input.next();

? ? ? ? ? ? ? ? ? ? i = 1;

? ? ? ? ? ? ? ? ? ? if (choice.equals("f")) {

? ? ? ? ? ? ? ? ? ? student.put(s.Id, new Student(str1, str2));

? ? ? ? ? ? ? ? ? ? break;

}

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? if(i==0){

? ? ? ? ? ? ? ? System.out.println("您輸入的學(xué)生名字不存在!");

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? }

剛剛那個錯了,那個成了只修改映射中ID為1的學(xué)生ID了,這個就沒問題了

http://img1.sycdn.imooc.com//5731b7130001b0db19201080.jpg

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

如果繁星能來到我身邊 提問者

為什么我就不可以呢。。。
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~
#2

如果繁星能來到我身邊 提問者

麻煩高手再幫我看看,我的疑問在下面的回復(fù)里面。。。
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~

運行結(jié)果

http://img1.sycdn.imooc.com//5731b5fc0001630710000562.jpg


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

關(guān)于已知學(xué)生名字,修改其ID。希望大神可以指點我一下。。。

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號