About Question enthuware.ocpjp.v7.2.1427 :

Moderator: admin

Post Reply
vijayanand
Posts: 10
Joined: Fri Sep 26, 2014 8:40 am
Contact:

About Question enthuware.ocpjp.v7.2.1427 :

Post by vijayanand » Mon Oct 27, 2014 11:45 pm

arg[0] is "\s[\d]*\s"

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

admin
Site Admin
Posts: 7411
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Tue Oct 28, 2014 8:34 pm

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.
If you like our products and services, please help us by posting your review here.

maderkse
Posts: 4
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

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

Post by maderkse » Thu Sep 13, 2018 4:01 pm

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.

admin
Site Admin
Posts: 7411
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Thu Sep 13, 2018 10:26 pm

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.

thank you for your feedback
If you like our products and services, please help us by posting your review here.

maderkse
Posts: 4
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

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

Post by maderkse » Fri Sep 14, 2018 5:42 am

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

maderkse
Posts: 4
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

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

Post by maderkse » Fri Sep 14, 2018 5:47 am

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

admin
Site Admin
Posts: 7411
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Sat Sep 15, 2018 12:46 am

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.
If you like our products and services, please help us by posting your review here.

maderkse
Posts: 4
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

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

Post by maderkse » Sat Sep 15, 2018 6:59 am

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

admin
Site Admin
Posts: 7411
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Sat Sep 15, 2018 11:28 am

So it could be that the behavior is different on Linux.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests