zoukankan      html  css  js  c++  java
  • 编程实践65

    编程实践6-5

    课程元素类型 任务

    定义函数,计算a+aa+aaa+...+a…a,共n项,其中a、n由键盘输入,a是[1,9]间的数字。

    using System;
    
    namespace sj_6_5
    {
        class Program
        {
            static void Main(string[] args)
            {
                int a, n;
    
                Console.Write("请输入A的值:\n");
                a = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入N的值:\n");
                n = Convert.ToInt32(Console.ReadLine());
    
                Console.WriteLine(js(a, n));
    
                Console.ReadKey();
            }
            public static int js(int x, int y)
            {
                int c;
                string d;
                c = x;
                d = "11";
                for (int i = 0; i < y - 1; i++)
                {
                    c = c + x * Convert.ToInt32(d);
                    d = d + "1";
                }
                return c;
            }
        }
    }

    .版本2

    using System;
    
    namespace sj_6_5
    {
        class Program
        {
            static void Main(string[] args)
            {
                int a, n;
    
                Console.Write("请输入A的值:\n");
                a = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入N的值:\n");
                n = Convert.ToInt32(Console.ReadLine());
    
                Console.WriteLine(js(a, n));
    
                Console.ReadKey();
            }
            public static int js(int x, int y)
            {
                int a = 0,c = 0;
                
                for (int i = 0; i < y; i++)
                {
                    a = a * 10 + x;
                    c = c + a;
                }
                return c;
            }
        }
    }
  • 相关阅读:
    多线程
    序列化
    IO流
    递归
    JAVA异常处理
    java常用类-StringBuffer,Integer,Character
    系统测试过程
    备份,健壮,文档,在线帮助,网络,稳定性测试
    异常测试/恢复性测试(可靠)
    配置测试
  • 原文地址:https://www.cnblogs.com/Wzqa/p/2812344.html
Copyright © 2011-2022 走看看