Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (anonymous):

What is use of useDelimeter() method in java?

OpenStudy (anonymous):

In Second part of the code with ## ,I write two words and enter but not working.What should i do? package deneme; import java.util.Scanner; public class DelimetersDemo { public static void main(String[] args) { Scanner keyboard1 = new Scanner(System.in); Scanner keyboard2 = new Scanner(System.in); keyboard2.useDelimiter("##"); //The delimiters for keyboard1 are the white space characters. //The only delimiter for keyboard2 is ##. String s1, s2; System.out.println("Enter a line of text with two words:"); s1 = keyboard1.next( ); s2 = keyboard1.next( ); System.out.println("The two words are \"" + s1 + "\" and \"" + s2 + "\""); System.out.println("Enter a line of text with two words"); System.out.println("delimited by ##:"); s1 = keyboard2.next( ); s2 = keyboard2.next( ); System.out.println("The two words are \"" + s1 + "\" and \"" + s2 + "\""); } }

OpenStudy (asnaseer):

A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. keyboard2 is told to set the delimiter to ## which means each token has to be separated by a double #. e.g. entering "hello world" (without the quotes) for keyboard1 will set s1="hello" and s2="world" similarly, entering "hello##world" (without the quotes) for keyboard2 will s1="hello" and s2="world"

OpenStudy (anonymous):

Thanks=)

OpenStudy (asnaseer):

yw

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!