如何打印一定数量的字符? [英] How do I print certain amount of characters?

查看:79
本文介绍了如何打印一定数量的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程C#的初学者。我有一个任务,要求创建一个程序并输入一个需要打印的符号,一行打印的最大符号数和根据选择打印多少个符号(例如在控制台中输入0-100 i) 54,它打印出54个符号)。



我尝试过:



尝试在互联网上查看如何输入一定数量字符的示例。

解决方案

要输入,您可能需要使用Console.ReadLine:

  string  input = Console.ReadLine(); 

然后你可以转换使用TryParse对数字的第二个输入:

  int  count; 
string countAsString = Console.ReadLine();
if (!int.TryParse(countAsString, out count))
{
Console.WriteLine( \{0} \不是数字!,countAsString);
}
其他
{
// < span class =code-comment> count现在包含用户输入的数字。
...在此处理您的计数和符号...
}


I'm a beginner at programming C#. I have a task which asks to create a program and input a symbol which needs to be printed, max number of symbols printed in one line and how many symbols you could print based on choice(for example like from 0-100 i input in console 54 and it prints out 54 symbols).

What I have tried:

Have tried looking on the internet for examples on how to input a certain amount of characters.

解决方案

To input, you probably need to use Console.ReadLine:

string input = Console.ReadLine();

You can then convert the second input to a number using TryParse:

int count;
string countAsString = Console.ReadLine();
if (!int.TryParse(countAsString, out count))
   {
   Console.WriteLine("\"{0}\" is not a number!", countAsString);
   }
else
   {
   // count now contains the number the user entered.
   ... process your count and symbols here ...
   }


这篇关于如何打印一定数量的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆