-2

So basically I'm trying to write a method that takes 2 strings as parameters and returns a boolean. It returns true if t occurs as a token within s, and returns false if otherwise.

I'm pretty new to coding so I don't really know what i'm doing wrong, any help is appreciated!

Here's my code:

public static boolean containsToken(String s, String t) {

 Scanner scr = new Scanner(s);

This scanner breaks up String s into tokens

for(int i = 0; i < s.length(); i++) {

I tried to make this for loop search through the length of s for tokens that match up with String t

if(t.contains(scr.next()))

return true;
}
return false; 


} 

1 Answers1

0

Scanner is predominantly used for taking inputs from a stream like system.in. Since you are provided with the whole string from the start you can tokenize it however fits your need with split

lvoelk
  • 2,390
  • 1
  • 12
  • 16