1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
andreyandreev [35.5K]
3 years ago
6

Write C# program that will read name from keyboard and display it on screen. The program should throw an exception when the leng

th of name is more than 15 character.
Computers and Technology
1 answer:
Hitman42 [59]3 years ago
4 0

Answer:

       static void Main(string[] args)

       {

           try

           {

               Console.Write("Enter your name: ");

               string name = Console.ReadLine();

               if (name.Length > 15)

               {

                   throw new Exception($"Name length {name.Length} is too long, max 15!");

               }

               else

               {

                   Console.WriteLine("Hello " + name);

               }

           }  

           catch(Exception ex)

           {

               Console.WriteLine("Exception occurred: " + ex.Message);

           }

       }

Explanation:

This is one way of doing it. More elaborate is to subclass Exception into NameLengthException and throw that.

You might be interested in
Assume user_name equals "Tom" and user_age equals 22. What is printed on the console when the following statement is executed? c
12345 [234]

Answer:

The ouput of the given code is :

22

is "Tom's age.

Explanation:

Here in this code the variable user_name and user_age are initialized to  "Tom" and 22 respectively as statement is given in the question i.e  cout << user_age << " \nis " + user_name << "'s age.";.This line will print the user_age i.e 22 after that the control moves to the next line and print is "Tom's age.

Following are the code in c++

#include <iostream> // header file

#include <string>

using namespace std;

int main() // main function

{

   string user_name="Tom";

   int user_age= 22;

cout << user_age << " \nis " + user_name << "'s age.";

return 0;

}

Output:

22

is "Tom's age.

8 0
3 years ago
PLSSSSS HELPP!! Tropical rainforests are home to many kinds of birds, including parrots, toucans and eagles. Each different spec
Elanso [62]

Answer:

C I believe

Explanation:

5 0
3 years ago
Read 2 more answers
Your baby brother has found the hammer and is eagerly eyeing one of the boxes. Describe and analyze an algorithm to determine if
erastovalidia [21]

Answer:

Question is incomplete.

Assuming the below info to complete the question

You have a collection of n lockboxes and m gold keys. Each key unlocks at most one box. Without a matching key, the only way to open a box is to smash it with a hammer. Your baby brother has locked all your keys inside the boxes! Luckily, you know which keys (if any) are inside each box.

Detailed answer is written in explanation field.

Explanation:

We have to find the reachability using the directed graph G = (V, E)

In this V are boxes are considered to be non empty and it may contain key.

Edges E will have keys .

G will have directed edge b1b2 if in-case box b1 will have key to box b2 and box b1 contains one key in it.

Suppose if a key opens empty box or doesn’t contain useful key means can’t open anything , then it doesn’t belongs to any edge.

Now, If baby brother has chosen box B, then we have to estimate for other boxes reachability from B in Graph G.

If and only if all other boxes have directed path from box B then just by smashing box B we can get the key to box b1 till last box and we can unlock those.

After first search from B we can start marking all other vertex of graph G.

So algorithm will be O ( V +E ) = O (n+m) time.

7 0
3 years ago
What is looping in QBASIC​
Elden [556K]

A looping is a set of instructions which is repeated a certain number of times until a condition is met. hlo dai k xa halkhabar

3 0
3 years ago
Hey, how do we get our warnings removed? I got one and I didn't realize that what I did was wrong.
vodka [1.7K]

Sorry we can't remove our warnings

5 0
2 years ago
Read 2 more answers
Other questions:
  • During the past decade ocean levels have been rising faster than in the past, an average of approximately 3.1 millimeters per ye
    14·1 answer
  • How long does it take a letter to arrive?
    9·1 answer
  • Not providing guarding or fall protection for workers on a 25-foot scaffold. The resulting fall would most likely end in death,
    6·1 answer
  • Develop a Java program that determines the gross pay for an employee. The company pays hourly rate for the first 40 hours worked
    8·1 answer
  • Briefly describe the client/server model.
    8·1 answer
  • __________ is a growing practice in cooperative farmingassociations to pool and sell the fruit as a common commodity underthe br
    6·1 answer
  • The acronym pies is used to describe improvised explosive devices (ied) components. pies stands for:
    13·2 answers
  • A recommended cleaner for the bowls of coffee brewers is
    7·1 answer
  • Need answer ASAP.
    8·1 answer
  • The notes added to slides can be seen during the presentation. TRUE OR FALSE​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!