Page 1 of 1

About Question enthuware.ocpjp.v7.2.1427 :

Posted: Mon Oct 27, 2014 11:45 pm
by vijayanand
arg[0] is "\s[\d]*\s"

Shouldn't it be "\\s[\\d]*\\s" ?

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Tue Oct 28, 2014 8:34 pm
by admin
No, since you are supposed to type it on the command line, you don't need to using \\. \\ is required when you put it as a String in the code.

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Thu Sep 13, 2018 4:01 pm
by maderkse
The command line arguments given in the question are: \s[\d]*\s "12 3abc ab23". The double quotes are missing in the first argument. Perhaps you can correct this. Without the quotes it's not working as should.

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Thu Sep 13, 2018 10:26 pm
by admin
The issue is not with the quotes. There seems to be an extra / at the beginning, which should not be there. I tried it just now. It compile and runs fine without producing any output just as the correct option says.

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Fri Sep 14, 2018 5:42 am
by maderkse
The difference between quotes and without quotes will only show when something is found. Below in the picture you see my sample code, an example without quotes and with quotes. It should find " 1 " but it fails in the example without quotes. (OS is Linux)

Image

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Fri Sep 14, 2018 5:47 am
by maderkse
The picture link is not working in my previous post. Below, I pasted the terminal text, which is the same content as in the picture.

[12:27 tmp ]$ cat R8.java

Code: Select all

import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class R8 {
   public static void main(String[] args) {
      System.out.println("Hi " + R8.class.getSimpleName() + " here!");

      Pattern p = Pattern.compile(args[0]);
      Matcher m = p.matcher(args[1]);
      boolean find = false;
      while (find = m.find()) {
         System.out.println(m.start() + m.group());
      }
   }
}
[12:27 tmp ]$ java R8 \s[\d]*\s " 1 "
Hi R8 here!
[12:28 tmp ]$ java R8 "\s[\d]*\s" " 1 "
Hi R8 here!
0 1

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Sat Sep 15, 2018 12:46 am
by admin
Can you tell me which JDK version are you using? Because I am running it on Win 10 with JDK 1.8.0.121 and when I run it with arguments \s[\d]*\s " 1 "
it prints 0 1.

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Sat Sep 15, 2018 6:59 am
by maderkse

Code: Select all

[13:54 ~ ]$ java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
[13:55 ~ ]$ uname -a
Linux localhost 4.4.111-13688770-QB19092629 #1 SMP PREEMPT Wed Jul 25 16:14:55 KST 2018 aarch64 GNU/Linux

Re: About Question enthuware.ocpjp.v7.2.1427 :

Posted: Sat Sep 15, 2018 11:28 am
by admin
So it could be that the behavior is different on Linux.