Which code should you insert at line 03?

You are creating a console application named App1.
App1 will validate user input for order entries.
You are developing the following code segment (line numbers are included for reference only):

You need to complete the code segment.
The solution must ensure that prices are positive and have two decimal places.
Which code should you insert at line 03?

You are creating a console application named App1.
App1 will validate user input for order entries.
You are developing the following code segment (line numbers are included for reference only):

You need to complete the code segment.
The solution must ensure that prices are positive and have two decimal places.
Which code should you insert at line 03?

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
* Regex.IsMatch Method (String, String)
Indicates whether the specified regular expression finds a match in the specified input string.
Syntax:
public static bool IsMatch(
string input,
string pattern
)



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Hans Werner

Hans Werner

None of the given answers applies! It is said that the function has to ensure that there are two decimals. All of the regular expressions mark them as optional (“(\.\d\d)?”).

A valid regular expression would be “{0,-10}{1}”, as seen in this example:

Regex r = new Regex(@”^\d+\.\d\d$”);
Action a = (s) =>
{
Console.WriteLine(String.Format(“{0,-10}{1}”, s, r.IsMatch(s)));
};
a(“1”);
a(“1.0”);
a(“1.00”);
a(“1.000”);
a(“12”);
a(“12.0”);
a(“12.00”);
a(“12.000”);
a(“123”);
a(“123.0”);
a(“123.00”);
a(“123.000”);

Outputs:
1 False
1.0 False
1.00 True
1.000 False
12 False
12.0 False
12.00 True
12.000 False
123 False
123.0 False
123.00 True
123.000 False

Serge

Serge

I would answer C
I would eliminate A and B since Regex should be initialized.
also I would eliminate D since regex is a positive number.

Rajesh

Rajesh

Answer is C