• Post Reply Bookmark Topic Watch Topic
  • New Topic

A8.java:20: error: int cannot be dereferenced  RSS feed

 
Vanessa Laurent
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I'm VERY NEW  to Java. I keep getting the error- int cannot be dereferenced.
I just don't know what to do to get my code to run properly. Any tips would be greatly appreciated. thanks!





Return the number of times that the string "hi" appears anywhere in the given string.


countHi("abc hi ho") → 1
countHi("ABChi hi") → 2
countHi("hihi") → 2

2. Write a java program (in jGrasp) that has a main method and a method called countHi, with signature: public int countHi(String str).

In your main method, call countHi at least 12 times to test this method with different input values.
For each test, compare the method's returned value to the expected value and display a message indicating whether or not the method passed the test.




 
Wayan Saryada
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your checkOut() method you can't call equals() method on an int variable. Another thing, your class main() method must have a static modifier to make it runnable.
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Vanessa Laurent!

Thanks for trying to put your code in code tags.  You just need to be sure that the code tags surround the code.
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This test case is wrong
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about what you're passing as the second argument.  Should it really be a String?  And remember that if not, you should change the method signature here:
Now this line...... becomes less problematic.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!