java.util.scanner - find in line java object , how to scan all the input? -


An investigation is going on in searching the IIM inline object but it is not working and I do not know why it The code is:

  public static zero main (string [] args) {scanner input = new scanner (System.in); System.out.print ("Enter String:"); String A = Null; String pattern = "(,)"; If (input.findInLine (pattern)! = Null) {a = input. NextLine (); } System.out.println (a);   

Enter the string: (9) & lt; ---------- This is what I have written

this output: 9)

What do I do If I want that variable a will get all the strings I wrote like this: A = (9) and not a = 9) < / Code>

Whatever I think you want to input some string and if that string is your pattern , Which you should be shown in the console. This will give you the right output.

  import java.util.Scanner; Public class InputScan {public static zero main (string [] args) {scanner input = new scanner (System.in); String A; System.out.print ("Enter String:"); String pattern = "\\ (\\ d +, \\ d + \\)"; // its regex // like you have regex // string pattern = "\\ ([\\ s +]? \\ d + [\\ s +] ?, [\\ s +] + \ \ d + [ \\ s +]? \ \\ s +] \\)? "; If ((a = input.findInLine (pattern)) = null {System.out.println (a); }}   

Input:

  (9 9)   

Output:

  (9)    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -