Up, working on my java skills.
The isDelimiter function is suppose to return true if there is a delimiter in the string and false otherwise. The main is suppose to call this function and count the number of words in the string:
Here is what I came up with:
import java.util.*; public class NumberOfWordsInString { public static void main (String[] args){ Scanner in= new Scanner (System.in); String s; int count =0; char ch [] = new char [s.length]; System.out.printf("Enter string\n"); s= in.nextLine(); for (int i = 0; i <s.length(); i++) { ch[i] = s.charAt(i); if (isDelimiter (ch)) { count ++; } } System.out.printf("%d\n", count); } public static boolean isDelimiter (char c){ if (ch!= delimiter) { return false; } else return true; } }
Somehow my method isn't being successfully called by my main and the following error msg was received:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
length cannot be resolved or is not a field
The method isDelimiter(char) in the type NumberOfWordsInString is not applicable for the arguments (char[])
at javaimprovements.NumberOfWordsInString.main(Number OfWordsInString.java:10)
line 10:
char ch [] = new char [s.length];
and the main doesn't call the isDelimiter function