本文介绍了编写一个接受整数(n)的C#程序,并计算n + nn + nnn的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 到目前为止,我只能弄清楚如何允许用户输入整数。 我尝试过: So far I have only been able to figure out how to allow the user to input an integer.What I have tried:using System;namespace ConsoleApp1{ class Program { static void Main(string[] args) { Console.WriteLine("Input integer"); //ask user to input integer String n = Console.ReadLine(); string nn = Console.ReadLine(); string nnn = Console.ReadLine(); //allows user to input integer } }} 推荐答案 72 + 7272 + 727272 = 734616 你不这样做:你试图读三个值。 这是你的作业,所以我不会给你任何代码。但它非常简单: 1)将用户的值读入字符串 - > n $ / b $ b)创建一个新字符串nn并将原始字符串追加两次 3)创建一个新字符串nnn并将原始字符串追加三次 4)将每个字符串转换为数值:检查您的注释,您将找到Convert.ToInt32(基本和坏)或int.TryParse的信息(更好,但更难使用)。将它们放入三个新的整数变量iN,iNN和iNNN。 5)将iN,iNN和iNNN加在一起,然后打印结果。You aren't doing that: you are trying to read three values.This is your homework, so I'll give you no code. But it's pretty simple:1) Read a value from the user into a string -> n2) Create a new string nn and append the original string twice3) Create a new string nnn and append the original string three times4) Convert each of these strings to a numeric value: check your notes and you'll find information of either Convert.ToInt32 (basic and bad) or int.TryParse (much better, but harder to use). put them in three new integer variables iN, iNN, and iNNN.5) Add together iN, iNN, and iNNN, then print the result. Quote:编写一个接受整数(n)的C#程序,并计算n + nn + nnn的值。Quote: 假设n< 10. nn = 10 * n + n nnn = 100 * n + 10 * n + n 如果你把n读作一个字符串,你可以通过将n连接到它自己来构建nn和nnn。Assuming that n < 10.nn = 10 * n + nnnn = 100 * n + 10 * n + nIf you read n as a string, you can build nn and nnn by concatenating n to itself. 这篇关于编写一个接受整数(n)的C#程序,并计算n + nn + nnn的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 19:19