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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Scanner工具類的初始化問題,求大神

  • //父類

package text2;


public class vehicle {

? ? ? ?public void transport(){

? ? ? System.out.println("交通工具具有運(yùn)輸?shù)哪芰?);

? ? ? ?}

? ? ? ?public int site;//載客數(shù)

? ? ? ?public String transMode;//運(yùn)送方式

? ? ??

? ? ? ?public void operation(){

? ? ? ? ? ?

? ? ? ?}

}

  • //子類

package text2;


public class car extends vehicle {

int site=1;

? ? String transMode="land";

? ? public void operation(){

? ? ? ? System.out.println("汽車可載客"+site+"人,運(yùn)送方式為"+transMode);

? ? ? ? ? ? ? ? ?

? ? }

}

  • //子類

package text2;


public class plane extends vehicle {

int site=150;

? ? String transMode="fly";

? ? public void operation(){

? ? ? ? System.out.println("飛機(jī)可載客"+site+"人,運(yùn)送方式為"+transMode);

? ? ? ? ? ? ? ? ?

? ? }

}

  • //子類

package text2;


public class train extends vehicle {

int site=1500;

? ? String transMode="land";

? ? public void operation(){

? ? ? ? System.out.println("火車可載客"+site+"人,運(yùn)送方式為"+transMode);

? ? ? ? ? ? ? ? ?

? ? }

}

  • //方法

package text2;

import java.util.Scanner;

public class inital {


public static void main(String[] args) {

// TODO Auto-generated method stub

? ? vehicle car=new car();

? ? vehicle plane=new plane();

? ? vehicle train=new train();

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

? ? System.out.println("請(qǐng)輸入查詢的對(duì)象:");

? ? String Name=input.next();

? ? String a="plane";

? ? String b="train";

? ? String c="car";

? ? if(Name.equals(a)){

? ? plane.operation();

? ? }else if(Name.equals(b)){

? ? train.operation();

? ? }else if(Name.equals(c)){

? ? car.operation();

? ? }else{

? ? ? ? System.out.println("!請(qǐng)檢查輸入的對(duì)象名稱");

? ? }

? ? input.close();

}


}


問題就是每次執(zhí)行的時(shí)候只能查詢一次,輸錯(cuò)了回車執(zhí)行之后也不能重新輸入,怎么樣可以多次查詢啊



正在回答

4 回答

public?class?Transport?{
	public?static?void?main(String[]?args){
		String?n="x";
		Trans?obj1=new?Jiaoche();
		Trans?obj2=new?Feiji();
		Trans?obj3=new?Zixingche();
		Trans?obj4=new?Sanlunche();
		Trans?obj5=new?Motuoche();
		while(n!=?null){
		Scanner?in=new?Scanner(System.in);
		System.out.println("請(qǐng)輸入要查找的對(duì)象");
		String?name=in.next();
		String?a="轎車";
		String?b="飛機(jī)";
		String?c="自行車";
		String?d="三輪車";
		String?e="摩托車";
		
		if(name.equals(a)){
		obj1.yunshu();
		}
		if(name.equals(b)){
			obj2.yunshu();
			}
		if(name.equals(c)){
			obj3.yunshu();
			}
		if(name.equals(d)){
			obj4.yunshu();
			}
		if(name.equals(e)){
			obj5.yunshu();
			}
		}
	}
}

只弄了while那里的代碼,我自己是了是可以的,你可以改一下

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


while(boolean?a=true)
a=對(duì)象.方法();????????????????//方法需要結(jié)束返回false


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

while (true) {

int s = input.nextInt();

System.out.println(s);

if (s == 0) {//循環(huán)終止條件

break;


}

}

input.close();


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

while(input.hasNext){主代碼段} ? ?可行否? ?

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

小幕1314 提問者

不行額
2016-07-26 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門第二季 升級(jí)版
  • 參與學(xué)習(xí)       531098    人
  • 解答問題       6280    個(gè)

課程升級(jí)!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙

進(jìn)入課程

Scanner工具類的初始化問題,求大神

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

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

幫助反饋 APP下載

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

公眾號(hào)

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