CJCoding With Joseph
15free / daySign inCreate account

A variable text starts as null. Read an integer cmd; if cmd == 1, set text = "hello". Then print Length: <text.Length>. If text is still null, accessing .Length throws a NullReferenceException; catch it and print Text was null. Use top-level statements with try/catch.

Input 1 prints: Length: 5 Input 0 prints: Text was null

Expected output

Length: 5

= newline. The output ends with a newline, so print one after the last line.

Hints2 available
Topics
Exceptions
Auto-input
1\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.