1. Engineering
  2. Computer Science
  3. i am trying to write a java function that will...

Question: i am trying to write a java function that will...

Question details

I am trying to write a java function that will count the number of ints in the string but I keep getting an error.

here is my function.

76 Returns the number of tokens (as identified by the s.next) method on Scanners s) in the parameter sentence that are not an int, as identified by s.hasNextInt). For example, countTokensThatAreNotInt(this is 12 a test) should return 4, and countTokensThatAreNotInt(12 should return 0 78 79 80 81 82 83 84 85 86 87 IMPLEMENTATION NOTE:This will require a while loop. Use a Scanner to split the string into individual words. Use an if statement to figure out whether to count the token or not. *Replace this comment with your own Javados comment public static int countTokensThatAreNotInt(String sentence) 89 90 91 92 93 94 95 96 97 int nonInts-0; Scanner s = new Scanner(sentence); while (s.hasNextO&&(int) ch >= 48 ll (int) sh <= 57) { s.next(); nonInts++ return nonIntS;

Here is where I call it

26 public class MethodCollection i 27 28 29 30 31 32 In main, write code that exercises all the methods you write. This code should call the methods with different arguments and print out results. You should think about different arguments to try that tests different cases. For k example, if the method returns a true or false, write code that creates a k to explain what each test is checking and the result that was obtained. k different methods. true result and other code that produces a false result. Use print statements 34 35 36 37 38 39 40 public static void main(String [] args) 41 42 43 Running this program should output a small report on examples of using the * Replace this comment with your own Javados comment System.out.println (Hello); String testThis is a test 12; int numberTokenscountTokens (test); System.out.println(countTokens found numberTokenson test input:+ test) int numOfNonInts countTokensThatAreNotInt(test); countTokensThatAreNotInt(test); System.out.println(countTokensThatAreNotInt found +numOfNonIntst on test input: 45 46 47 48 49

This is my error:

Problems @ Javadoc Declaration Console E3 <terminated> MethodCollection [Java Application] /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/bin/java (Jan countTokens found 5 on test input: This is a test 12 Exception in thread main java. lang.Error: Unresolved compilation problems: ch cannot be resolved to a variable ch cannot be resolved to a variable at a2.MethodCollection.countTokensThatAreNotInt (MethodCollection.java:91) at a2.MethodCollection.main(MethodCollection.java:45)

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution