如题所述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入字符串:");
string str = Console.ReadLine();
int a1 = 0;
foreach (var item in str)
{
if (int.TryParse(item.ToString(), out a1) == false) //判断是否是数字
{
Console.Write(item.ToString());
}
}
Console.WriteLine("-----------------------------------");
int[][] num = new int[2][];
for (int i = 0; i < num.Length; i++)
{
num[i] = new int[9]; //声明第二数组长度
}
for (int i = 0; i < num.Length; i++)
{
for (int j = 0; j < num[0].Length; j++)
{
num[i][j] = j + 1; //赋值
}
}
int a = 0, b = 0, c = 0;
for (int i = 0; i < num[0].Length; i++)
{
for (int j = 0; j <= i; j++)
{
a = num[0][i];
b = num[1][j];
c = a * b;
Console.Write(string.Format("{0}*{1}={2}\t ", a, b, c)); //按格式打印结果
}
Console.WriteLine("\t");
}
Console.WriteLine("-----------------------------------");
bool isSushu = true;
int k;
List<int> li = new List<int>();
Console.Write("正序打印50以内的素数:");
for (int i = 2; i < 50; i++)
{
k = 0;
for (int j = 1; j < i; j++)
{
if (i % j == 0)
{
k++;
if (k > 1)
{
isSushu = false; //判断是否是素数
}
else
{
isSushu = true;
}
}
}
if (isSushu)
{
li.Add(i); //将结果添加到集合中
Console.Write(i + " ");
}
}
Console.Write("\n倒序打印50以内的素数:");
var v = (from c2 in li orderby c2 descending select c2).ToList(); //查找结果并排序 也可以用循环来做
v.ForEach(s => Console.Write(s + " ")); //循环打印
Console.WriteLine("\n-----------------------------------");
List<StudentFenshu> Lsf = new List<StudentFenshu>();
StudentFenshu student;
for (int i = 1; i < 5; i++) //获得学生信息
{
student = new StudentFenshu();
try
{
Console.WriteLine("请输入第{0}学生姓名:", i);
student.SName = Console.ReadLine();
Console.WriteLine("请输入该学生的语文成绩:(请输入数字)");
student.YuCJ = int.Parse(Console.ReadLine());
Console.WriteLine("请输入该学生的数学成绩:(请输入数字)");
student.SuCJ = int.Parse(Console.ReadLine());
Console.WriteLine("请输入该学生的英语成绩:(请输入数字)");
student.YuCJ = int.Parse(Console.ReadLine());
Lsf.Add(student);
Console.WriteLine("保存成功!");
}
catch (Exception e)
{
Console.WriteLine("输入参数类型错误!请重新输入" + e.ToString());
i--;
}
}
Console.WriteLine("语文成绩由高到低的同学成绩如下:");
var yuwen = (from y in Lsf orderby y.YuCJ descending select new { y.SName, y.YuCJ }).ToList(); //查找对应结果并排序
yuwen.ForEach(s => Console.WriteLine(String.Format("{0}\t {1}", s.SName, s.YuCJ))); //打印结果,以下同上
Console.WriteLine("数学成绩由高到低的同学成绩如下:");
var shuxue = (from y in Lsf orderby y.SuCJ descending select new { y.SName, y.SuCJ }).ToList();
shuxue.ForEach(s => Console.WriteLine(String.Format("{0}\t {1}", s.SName, s.SuCJ)));
Console.WriteLine("数学成绩由高到低的同学成绩如下:");
var yingyu = (from y in Lsf orderby y.EnCJ descending select new { y.SName, y.EnCJ }).ToList();
yingyu.ForEach(s => Console.WriteLine(String.Format("{0}\t {1}", s.SName, s.EnCJ)));
Console.WriteLine("-------------------------------------------");
string userID = "";
string pwd = "";
int b4=0;
bool JianYan = false;
const string PWD = "admin123";
while (true)
{
Console.WriteLine("请输入用户名:(用户名不超过6位)");
userID = Console.ReadLine();
if (userID.Length > 6 || userID == "") //判断用户名长度及是否输入为空
{
Console.WriteLine("用户名超过六位,请重新输入:");
}
else
{
Console.WriteLine("请输入密码:(密码不能全部为数字:)");
pwd = Console.ReadLine();
foreach (var item in pwd)
{
if (int.TryParse(item.ToString(), out b4) == false) //判断密码类型 有字母则为真 否则为假
{
JianYan = true;
break;
}
else
{
JianYan= false;
}
}
if (JianYan)//判断是否跟预定密码符合
{
if (pwd == PWD)
{
Console.WriteLine("欢迎...");
break;
}
else
{
Console.WriteLine("密码错误!!请重新输入");
}
}
else
{
Console.WriteLine("密码不能全为数字,请重新输入");
}
}
}
}
}
/// <summary>
/// 定义学生类
/// </summary>
public class StudentFenshu {
public string SName{get;set;}
public int YuCJ{get;set;}
public int SuCJ{get;set;}
public int EnCJ { get; set; }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入字符串:");
string str = Console.ReadLine();
int a1 = 0;
foreach (var item in str)
{
if (int.TryParse(item.ToString(), out a1) == false) //判断是否是数字
{
Console.Write(item.ToString());
}
}
Console.WriteLine("-----------------------------------");
int[][] num = new int[2][];
for (int i = 0; i < num.Length; i++)
{
num[i] = new int[9]; //声明第二数组长度
}
for (int i = 0; i < num.Length; i++)
{
for (int j = 0; j < num[0].Length; j++)
{
num[i][j] = j + 1; //赋值
}
}
int a = 0, b = 0, c = 0;
for (int i = 0; i < num[0].Length; i++)
{
for (int j = 0; j <= i; j++)
{
a = num[0][i];
b = num[1][j];
c = a * b;
Console.Write(string.Format("{0}*{1}={2}\t ", a, b, c)); //按格式打印结果
}
Console.WriteLine("\t");
}
Console.WriteLine("-----------------------------------");
bool isSushu = true;
int k;
List<int> li = new List<int>();
Console.Write("正序打印50以内的素数:");
for (int i = 2; i < 50; i++)
{
k = 0;
for (int j = 1; j < i; j++)
{
if (i % j == 0)
{
k++;
if (k > 1)
{
isSushu = false; //判断是否是素数
}
else
{
isSushu = true;
}
}
}
if (isSushu)
{
li.Add(i); //将结果添加到集合中
Console.Write(i + " ");
}
}
Console.Write("\n倒序打印50以内的素数:");
var v = (from c2 in li orderby c2 descending select c2).ToList(); //查找结果并排序 也可以用循环来做
v.ForEach(s => Console.Write(s + " ")); //循环打印
Console.WriteLine("\n-----------------------------------");
List<StudentFenshu> Lsf = new List<StudentFenshu>();
StudentFenshu student;
for (int i = 1; i < 5; i++) //获得学生信息
{
student = new StudentFenshu();
try
{
Console.WriteLine("请输入第{0}学生姓名:", i);
student.SName = Console.ReadLine();
Console.WriteLine("请输入该学生的语文成绩:(请输入数字)");
student.YuCJ = int.Parse(Console.ReadLine());
Console.WriteLine("请输入该学生的数学成绩:(请输入数字)");
student.SuCJ = int.Parse(Console.ReadLine());
Console.WriteLine("请输入该学生的英语成绩:(请输入数字)");
student.YuCJ = int.Parse(Console.ReadLine());
Lsf.Add(student);
Console.WriteLine("保存成功!");
}
catch (Exception e)
{
Console.WriteLine("输入参数类型错误!请重新输入" + e.ToString());
i--;
}
}
Console.WriteLine("语文成绩由高到低的同学成绩如下:");
var yuwen = (from y in Lsf orderby y.YuCJ descending select new { y.SName, y.YuCJ }).ToList(); //查找对应结果并排序
yuwen.ForEach(s => Console.WriteLine(String.Format("{0}\t {1}", s.SName, s.YuCJ))); //打印结果,以下同上
Console.WriteLine("数学成绩由高到低的同学成绩如下:");
var shuxue = (from y in Lsf orderby y.SuCJ descending select new { y.SName, y.SuCJ }).ToList();
shuxue.ForEach(s => Console.WriteLine(String.Format("{0}\t {1}", s.SName, s.SuCJ)));
Console.WriteLine("数学成绩由高到低的同学成绩如下:");
var yingyu = (from y in Lsf orderby y.EnCJ descending select new { y.SName, y.EnCJ }).ToList();
yingyu.ForEach(s => Console.WriteLine(String.Format("{0}\t {1}", s.SName, s.EnCJ)));
Console.WriteLine("-------------------------------------------");
string userID = "";
string pwd = "";
int b4=0;
bool JianYan = false;
const string PWD = "admin123";
while (true)
{
Console.WriteLine("请输入用户名:(用户名不超过6位)");
userID = Console.ReadLine();
if (userID.Length > 6 || userID == "") //判断用户名长度及是否输入为空
{
Console.WriteLine("用户名超过六位,请重新输入:");
}
else
{
Console.WriteLine("请输入密码:(密码不能全部为数字:)");
pwd = Console.ReadLine();
foreach (var item in pwd)
{
if (int.TryParse(item.ToString(), out b4) == false) //判断密码类型 有字母则为真 否则为假
{
JianYan = true;
break;
}
else
{
JianYan= false;
}
}
if (JianYan)//判断是否跟预定密码符合
{
if (pwd == PWD)
{
Console.WriteLine("欢迎...");
break;
}
else
{
Console.WriteLine("密码错误!!请重新输入");
}
}
else
{
Console.WriteLine("密码不能全为数字,请重新输入");
}
}
}
}
}
/// <summary>
/// 定义学生类
/// </summary>
public class StudentFenshu {
public string SName{get;set;}
public int YuCJ{get;set;}
public int SuCJ{get;set;}
public int EnCJ { get; set; }
}
}
温馨提示:答案为网友推荐,仅供参考