Task :
The only line contains the text. For each word in this text, calculate how many times it has been encountered in this text before.
A word is a sequence of non-blank characters in a row, words separated by one or more spaces or line breaks.
My decision course:
We read a string from the keyboard, determine how many words are in a string, create an array of type String . The length of the array is equal to the number of words in the string. In the array indices save each word. After we compare all the elements with each other and keep a counter.
My code is:
import java.util.Scanner; public class Semnadcat1 { public static void main(String[] args) { System.out.println("ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΡΠ΅ΠΊΡΡ"); Scanner in = new Scanner(System.in); String s = in.nextLine(); int a = s.split(" ").length; int i; String[] b = new String[a]; for (i = 0; i < a; i++) { for (String retval : s.split(" ")) { b[i] = retval; System.out.println(b[i]); } } } } Errors:
Cannot put words into array elements.
ΡΠ»ΠΎΠ²Π° ΡΠ°Π·Π΄Π΅Π»Π΅Π½Ρ ΠΎΠ΄Π½ΠΈΠΌ ΠΈΠ»ΠΈ Π±ΠΎΠ»ΡΡΠΈΠΌ ΡΠΈΡΠ»ΠΎΠΌ ΠΏΡΠΎΠ±Π΅Π»ΠΎΠ² ΠΈΠ»ΠΈ ΡΠΈΠΌΠ²ΠΎΠ»Π°ΠΌΠΈ ΠΊΠΎΠ½ΡΠ° ΡΡΡΠΎΠΊΠΈ"Π°Π°Π° Π±Π±Π±".split(" ").length- see what is"Π°Π°Π° Π±Π±Π±".split(" ").length. - post_zeew