.Net-C# 第一学期-第三章 上机练习+课后练习(简答题)


上机练习


上机练习2-
按规律生成输出一组数

上机练习3-
统计奇、偶数的个数

using System;

namespace demo13
{
    class Program
    {
    
    //两个都在里面
        class MyClass
        {
            public int[]  show()
            {
                int[] array = new int[30];
                array[0] = 1;
                array[1] = 1;
                for (int i = 2; i < array.Length; i++)
                {
                    array[i] = array[i - 1] + array[i - 2];
                }
                return array;
            }
            
            
}
        static void Main(string[] args)
        {
            MyClass class2=new MyClass();
            class2.show();
            int[] i =class2.show();
            int num=0;
            int num2=0;
            for (int j = 0; j < i.Length; j++)
            {
                Console.WriteLine(i[j]);
                if (i[j]%2==0)
                {
                    num++;
                }
                else
                {
                    num2++;
                }
            }
            Console.WriteLine("偶数{0},奇数{1}",num,num2);
        }
    }
}

.Net-C# 第一学期-第三章 上机练习+课后练习(简答题)_第1张图片

简答题

3.

using System;

namespace demo14
{
    class Program
    {
        public class Car
        {
            private string color;
            private string name;
            private string productPlace;

            public string Color { get => color; set => color = value; }
            public string Name { get => name; set => name = value; }
            public string ProductPlace { get => productPlace; set => productPlace = value; }
            public void Run()
            {
                Console.WriteLine("我是一辆{0},颜色是:{1},产地是:{2}", Name, Color, ProductPlace);
            }
        }
        
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("");
            Car car = new Car() { Name="奔驰-梅赛德斯",Color="高亮黑",ProductPlace="China"};
            car.Run();
        }
    }
}

5.

	//判断类
 public class Show
        {
            public int price;
            public int member;
            public int sumMember;

            public void show(int price,ref int member)
            {
                this.price = price/10;
                this.member = member;
                this.sumMember = member + this.price ;
            }
        }
        
        //测试类
static void Main(string[] args)
        {         
            Show show = new Show();
            Console.WriteLine("请输入购物金额:");
            int price = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入会员当前积分:");
            int member = int.Parse(Console.ReadLine());
            show.show(price, ref member);
            Console.WriteLine("本次购物消费:{0},新增积分:{1},当前积分:{2}" ,price,show.price,show.sumMember
                );
        }

你可能感兴趣的:(.Net—C#基础)