• 数组分析器


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                
                Console.Write("请输入数组的长度:");
                int arrLenght = int.Parse(Console.ReadLine());  //得到数组的长度
                int [] arr =new int[(int)arrLenght];   //初始化一个数组
                /*
                Console.Write("请输入数组的第1项:");
                arr[0] = int.Parse(Console.ReadLine());
                Console.Write("请输入数组的第2项:");
                arr[1] = int.Parse(Console.ReadLine());
                Console.Write("请输入数组的第3项:");
                arr[2] = int.Parse(Console.ReadLine());
                Console.Write("请输入数组的第4项:");
                arr[3] = int.Parse(Console.ReadLine());
                Console.Write("请输入数组的第5项:");
                arr[4] = int.Parse(Console.ReadLine());
                 
                 */
                for (int i = 0; i <=arr.Length-1; i++)
                {
                    Console.Write("请输入数组的第"+(i+1)+"项:");
                    arr[i] = int.Parse(Console.ReadLine());
                   
                }
                Console.Clear();
                //*******************************************************
                //已输入的值,重新生成数组,对数组进行排序(升序)
                for (int j = 0; j <=arr.Length-2; j++)
                {
                   // Console.WriteLine(arr[j]);
                    for (int k = j+1; k <=arr.Length-1; k++)
                    {
                        if(arr[j]>arr[k]){
                            int temp = arr[j];
                            arr[j] = arr[k];
                            arr[k] = temp;
    
                        }
                    }
                }
                //*******************************************************
                //打印显示,排序结果
                
    
                Console.WriteLine("您输入的数字排序后如下:");
                for (int l = 0; l <=arr.Length-1; l++)
                {
                    Console.Write(arr[l]+"	");                                         
                }
                Console.ReadLine(); //换行显示
                //*******************************************************
                //打印显示,奇数排序后的结果
                Console.WriteLine("其中,以下数字是奇数:");
                for (int t = 0; t <=arr.Length-1; t++)
                {
                    if(arr[t]%2!=0){
                        Console.Write(arr[t]+"	");
                    }
                }
                //*******************************************************
                //打印显示,质数排序后的结果
                Console.ReadLine();
                Console.WriteLine("以下数字是质数:");
                for (int y = 0; y <= arr.Length - 1; y++)
                {
                    bool isFind = false;  //判定数组中没有质数
                    for (int u = 2; u <=y-1; u++)
                    {
                        if(arr[y]%arr[u]==0){
                            isFind = true;  //找到不是质数的
                            break;
                        }
                    }
                    if (!isFind)
                    {
                        Console.Write(arr[y] + "	");
                    }
                    else {
                        Console.WriteLine("输入数字没有质数");
                    }
                }
    
                Console.ReadLine();
    
    
                /*
                 
                Console.WriteLine("您输入的数字排序后如下:");
                Console.WriteLine("其中,一下数字是奇数:");
                Console.WriteLine("以下数字是质数:");
                 */
    
            }
        }
    }
  • 相关阅读:
    s-hr实现单点登录,看我这份笔记就够了!!!
    S-HR类加载器的区别
    S-HR常用源码
    nginx安装配置参考
    make && make install
    Centos7提示Initial setup of CentOS Linux 7 (core)
    LinkedList的线程安全解决办法
    【开发笔记】- git回退版本: 回退本地代码版本 + 回退服务器代码版本
    【数据结构】- Java字节序、主机字节序和网络字节序扫盲贴
    【开发笔记】
  • 原文地址:https://www.cnblogs.com/asassa/p/9163842.html
Copyright © 2020-2023  润新知