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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在一行中輸入多個(gè)不同類型的變量?例如 ->

如何在一行中輸入多個(gè)不同類型的變量?例如 ->

臨摹微笑 2022-12-21 10:05:33
使用用 Java 實(shí)現(xiàn)的哈希表,我需要獲取 5 個(gè)輸入值,其中 3 個(gè)是字符串,2 個(gè)是整數(shù)。用戶必須能夠在一行中寫入所有輸入值。我嘗試了很多不同的方法,主要是使用數(shù)組,但我無(wú)法在網(wǎng)上找到正確的答案。如果有人可以幫助提供示例代碼或想法,我將不勝感激:)Scanner input = new Scanner(System.in);        Scanner input1 = new Scanner(System.in);        System.out.println("Enter number of people:");        int n = input1.nextInt();        HTable table = new HTable(100);        String a[] = new String[5];        for(int i=0; i<n; i++)        {            a = input.nextLine().split(" ");            table.Insert(a[0], a[1], Integer.parseInt(a[2]), a[3], Integer.parseInt(a[4]));        }這是我嘗試過(guò)的最新示例,但它一直在接受輸入并且 FOR() 循環(huán)似乎沒(méi)有結(jié)束。
查看完整描述

1 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

你可以這樣嘗試:


public class Name{

public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    System.out.println( "Enter Your Input ");

    while (scanner.hasNext()) 

    { 

        if (scanner.hasNextInt()) {

            System.out.println(" Your Value (Int) : " + scanner.nextInt());

        } else if (scanner.hasNextFloat()) {

            System.out.println(" Your Value (Float) " + scanner.nextFloat());

        } 

        else {

            System.out.println( " String Value(String) " + scanner.next());

        }

    }

查看完整回答
反對(duì) 回復(fù) 2022-12-21
  • 1 回答
  • 0 關(guān)注
  • 202 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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