このプログラムは、指定されたStringで使用可能な単語の数を表示するために書いています。 ここでは、occurenceof
のロジックを、組み込みのメソッドを使用せずに文字列内の各単語に入力します。私は、文字列を入力し、メソッドを組み込むことなく各ユニークワードの出現を表示するJavaプログラムを望みます
import java.util.Scanner;
public class Test80
{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
System.out.println("Enter your sentence:[Try to ignore space at end]");
String s=in.nextLine();
System.out.println("Size of the string is "+s.length());
int res=count(s);
System.out.println("No of words in the given String --->>"+" "+s+" :"+"is"+" :"+res);
}
private static int count(String s) {
int count=0;
if(s.charAt(0)!=' ')
{
count++;
}
for(int i=0;i<s.length();i++)
{
if((s.charAt(i)==' ')){
count++;
}
}
return count;
}
}
私はJavaの新しい学習者であるため、マップやハッシュテーブルを理解するために遠くまで行っていないので、私が持っているプロジェクトによれば、組み込みメソッドを使用せずにやる必要があります。 –
あなたの心配に感謝します。 –