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

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

將用戶輸入存儲(chǔ)在字符串?dāng)?shù)組中

將用戶輸入存儲(chǔ)在字符串?dāng)?shù)組中

尚方寶劍之說 2021-08-13 15:26:04
我是java初學(xué)者。我嘗試編寫一個(gè)程序來從命令行參數(shù)中讀取一系列單詞,并找到給定單詞的第一個(gè)匹配項(xiàng)的索引。喜歡用戶可以輸入“我愛蘋果”,給定的詞是“蘋果”。程序?qū)@示“'apple' 第一個(gè)匹配項(xiàng)的索引為 2”。到目前為止我所做的不起作用。這是我將輸入存儲(chǔ)到字符串?dāng)?shù)組中的方式不正確嗎?import java.util.Scanner;public class test {    public static void main(String [] args) {        System.out.println("Enter sentence: ");        Scanner sc = new Scanner(System.in);        String input = sc.nextLine();        int num=1;        String sentence[]=new String[num];        for(int i=0; i< num; i++) {          sentence[i] = input; // store the user input into the array.          num = num+1;        }        System.out.println("Enter the given words to find the index of its first match: ");        Scanner sc2 = new Scanner(System.in);        String key = sc2.next();         for(int j=0; j<num; j++) {            while (sentence[j].equals(key)) {                System.out.println("The index of the first match of "+key+" is "+j);            }        }    }   }
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 215 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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