About Question enthuware.ocpjp.v7.2.1427 :
Moderator: admin
-
- Posts: 10
- Joined: Fri Sep 26, 2014 8:40 am
- Contact:
About Question enthuware.ocpjp.v7.2.1427 :
arg[0] is "\s[\d]*\s"
Shouldn't it be "\\s[\\d]*\\s" ?
Shouldn't it be "\\s[\\d]*\\s" ?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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.
-
- Posts: 5
- Joined: Thu Sep 13, 2018 3:46 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Thu Sep 13, 2018 3:46 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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)
-
- Posts: 5
- Joined: Thu Sep 13, 2018 3:46 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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
[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
[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());
}
}
}
Hi R8 here!
[12:28 tmp ]$ java R8 "\s[\d]*\s" " 1 "
Hi R8 here!
0 1
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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.
it prints 0 1.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Thu Sep 13, 2018 3:46 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1427 :
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.
Who is online
Users browsing this forum: Bing [Bot] and 93 guests