标签:数字 失败 string 字符 程序 com 立方和 关键字 ogr
语法:
namespace _02.for循环的练习01
{
class Program
{
static void Main(string[] args)
{
//连续输出100次"我下次一定细心"
for (int i = 1; i <= 100; i++)
{
Console.WriteLine("{0}.我下次会小心.",i);
}
Console.ReadKey();
}
}
}
namespace _03.for循环的练习02
{
class Program
{
static void Main(string[] args)
{
//求1-100之间的所有偶数的和
int sum=0; //求和
for (int i = 1; i <= 100; i++)
{
if (i % 2 == 0)
{
sum += i;
}
}
Console.WriteLine("和为:{0}.",sum);
Console.ReadKey();
}
}
}
namespace _04.for循环的练习03
{
class Program
{
static void Main(string[] args)
{
//找出100-999之间的水仙花数
//所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身.
//例如:153是一个“水仙花数”,因为153 = 1的三次方+5的三次方+3的三次方。
int b; //保存百分位
int s; //保存十分位
int g; //保留个位
for (int i = 100; i <=999; i++)
{
b = i / 100; //获得百分位
s = (i / 10) % 10; //获取十分位
g = i % 10; //获取个位
if (Math.Pow(b, 3) + Math.Pow(s, 3) + Math.Pow(g, 3) == i)
{
Console.WriteLine(i);
}
}
Console.ReadKey();
}
}
}
namespace _05.for循环的练习04
{
class Program
{
static void Main(string[] args)
{
//输出乘法口诀表
for (int i = 1; i <=9; i++)
{
for (int j = 1; j <=9; j++)
{
Console.Write(j+"*"+i+"="+i*j+"\t");
if (j == i)
{
break;
}
}
Console.Write("\n");
}
Console.ReadKey();
}
}
}
namespace _06.for循环的练习05
{
class Program
{
static void Main(string[] args)
{
//请用户输入一个值:
//根据这个值可以输出一下加法表
//0+6=6;
//1+5=6;
//2+4=6;
//3+3=6;
//4+2=6;
//5+1=6;
//6+0=6;
Console.WriteLine("请输入一个数字:");
bool b = false; //用来确认是否要运行if语句中的内容
int number = 0; //用来保存输入的数字
try
{
number = int.Parse(Console.ReadLine());
b = true;
}
catch
{
Console.WriteLine("你输入的不是数字.");
}
if (b)
{
for (int i = 0, j=6; i <= 6&&j>=0; i++,j--)
{
Console.WriteLine(i + "+" + j + "=" + "{0}", i + j);
}
}
Console.ReadKey();
}
}
}
namespace _07.TryPaese的学习
{
class Program
{
static void Main(string[] args)
{
int number;
bool b=int.TryParse("123", out number);
Console.WriteLine(number);
Console.WriteLine(b);
Console.ReadKey();
}
}
}
namespace _07.TryPaese的学习
{
class Program
{
static void Main(string[] args)
{
int number;
bool b=int.TryParse("abc", out number);
Console.WriteLine(number);
Console.WriteLine(b);
Console.ReadKey();
}
}
}
标签:数字 失败 string 字符 程序 com 立方和 关键字 ogr
原文地址:http://www.cnblogs.com/HelloZyjS/p/6018827.html