Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

image text in transcribed

Here is where I call it

image text in transcribed

This is my error:

image text in transcribed

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 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago