簡體   English   中英

錯誤“找不到符號方法charAt(int)”?

[英]Error “Cannot find symbol method charAt(int)”?

System.out.println("Enter a sentence to get it translated into Pig Latin: ");

String sentence=kb.nextLine();

String[] words = sentence.split(" ");

char a=words.charAt(0);

發生的事情是words是一個數組,並且為String定義了charAt()方法。 因此,您想使用:

words[index].charAt(0)

相反,其中indexString在數組中的位置。

words是一個字符串數組。 嘗試使用words [index]。 分割后,子字符串將按以下方式存儲:

Enter = words[0]
a = words[1]
sentence = words[2]
to = words[3]
get = words[4]
it = words[5]
translated = words[6]
into = words[7]
Pig = words[8]
Latin: = words[9]

訪問word [index] .chartAt(0)將返回相應子字符串的第一個字符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM