什么是初学任务? [英] What is it missing beginner task?
本文介绍了什么是初学任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我是初学者,我需要一些帮助。我有一个任务,要求输入一定数量的符号,一行中的最大符号和符号本身。问题是,当我输入(9-> 6-> *)时,它打印出来:
******
*按任意键继续。 。 。
何时打印出来
******
*** >
So im a beginner and i need some help. Ive got a task which asks to input an amount of symbols, max symbols in one line and the symbol itself. The problem is that when i input (9->6->*) it prints out:
******
*Press any key to continue . . .
When it should print out
******
***
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sav
{
class Program
{
static void Main(string[] args)
{
char simbolis;
int k;
int x;
int a = 0;
Console.Write("iveskite norima kieki: ");
k = int.Parse(Console.ReadLine());
Console.Write("iveskite simboliu kieki eiluteje: ");
x = int.Parse(Console.ReadLine());
Console.Write("Įveskite spausdinamą simbolį: ");
simbolis = (char)Console.Read();
a = k / x;
int b = k % x;
for (int i = 1; i <= a; i++)
{
for (int j = 1; j<=x; j++)
{
Console.Write(simbolis);
}
Console.WriteLine();
}
if ( b > 0)
{
Console.Write(simbolis);
}
}
}
}
我尝试了什么:
花了10个小时试图找出这个bs
What I have tried:
Spent 10 hours trying to figure out this bs
推荐答案
你的主循环将只执行第一行,因为它从1到1.如果 b $ c中的值,则需要将<1加到 a
$ c>非零。为变量而不是单个字母使用合理的名称将有助于使其更清晰。此外,在最后一行 j
应该从1到 b
而不是1到 x
。
尝试在纸上写下步骤,以便更好地了解需要做什么。
Your main loop will only do the first line, as it goes from 1 to 1. You need to add 1 toa
if the value inb
is non-zero. Using sensible names for your variables rather than single letters would help to make that clearer. Also, on the last linej
should go from 1 tob
rather than 1 tox
.
Try writing the steps down on paper to get a better idea of what needs to be done.
>
这篇关于什么是初学任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文