Which code segment should you insert at line 03?

You are developing a game that allows players to collect from 0 through 1000 coins. You are creating
a method that will be used in the game. The method includes the following code. (Line numbers are
included for reference only.)
01 public string FormatCoins(string name, int coins)
02 {
03
04 }
The method must meet the following requirements:
Return a string that includes the player name and the number of coins.
Display the number of coins without leading zeros if the number is 1 or greater.
Display the number of coins as a single 0 if the number is 0.
You need to ensure that the method meets the requirements.
Which code segment should you insert at line 03?

You are developing a game that allows players to collect from 0 through 1000 coins. You are creating
a method that will be used in the game. The method includes the following code. (Line numbers are
included for reference only.)
01 public string FormatCoins(string name, int coins)
02 {
03
04 }
The method must meet the following requirements:
Return a string that includes the player name and the number of coins.
Display the number of coins without leading zeros if the number is 1 or greater.
Display the number of coins as a single 0 if the number is 0.
You need to ensure that the method meets the requirements.
Which code segment should you insert at line 03?

A.
Option A

B.
Option B

C.
Option C

D.
Option D



Leave a Reply 4

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


TheCoder

TheCoder

D – Pads 0’s for example 001 – the question stated without leading zeros’

Correct answer is A

Xano

Xano

Also D is wrong because the indexes should be 0 and 1 instead of 1 and 2.

Correct answer is A

Najlepszy Programista Swiata DAGO

Najlepszy Programista Swiata DAGO

A

Lord Vader

Lord Vader

https://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx

The “#” Custom Specifier
The “#” custom format specifier serves as a digit-placeholder symbol. If the value that is being formatted has a digit in the position where the “#” symbol appears in the format string, that digit is copied to the result string. Otherwise, nothing is stored in that position in the result string.
Note that this specifier never displays a zero that is not a significant digit, even if zero is the only digit in the string. It will display zero only if it is a significant digit in the number that is being displayed
e.g
value = 123;
Console.WriteLine(value.ToString(“#####”));
Console.WriteLine(String.Format(“{0:#####}”, value));
// Displays 123

A