using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
/*------------------------------- break 结束 -------------------------------*/
Console.WriteLine("输出1-500的数字,每行10个");
for (int i = 1; i < 501;i++ )
{
if ((i % 2 == 0) && (i % 3 == 0) && (i % 4 == 0) && (i % 5 == 0) && (i % 6 == 0) && (i % 7 == 0))
{
Console.Write(i);
Console.WriteLine();
Console.WriteLine(i+" 就是我们想要的那个数");
break;
}
//第10个数换行
if (i % 10 == 0)
{
Console.WriteLine(i);
}
else {
Console.Write(i+ " ");
if (i < 10) { Console.Write(" "); }
if (i < 100) { Console.Write(" "); }
}
}
/*------------------------------- continue 跳出------------------------------*/
Console.WriteLine("50以内的奇数有:");
for(int i=0;i<51;i++){
//如果是偶数跳出
if (i%2==0){
continue ; //continue 语句用于停止本次迭代 并非跳出迭代
}
Console.WriteLine(i + "\t"); //"\t" 空格
}
/*------------------------------- return 通过方法来实现------------------------------- */
//while (true) {
Console.WriteLine("请输入三个整数,按回车键确认每个数的输入");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int c = int.Parse(Console.ReadLine());
double average = (a + b + c) / 3;
Console.WriteLine("请输入三个整数的平均值时:{0}",average);
Console.ReadLine();
//}
/*------------------------------- go to 跳转-------------------------------*/
int aa = 0;
Console.WriteLine("5的阶乘等于几?根据以下选项选择正确的答案,回车键确认!");
Console.WriteLine("1. 5!=5\n2. 5!=10\n3. 5!=20\n4. 5!=60 ");
error:
{
aa++;
if (aa > 1) { Console.WriteLine("很遗憾,你答错了,请重新输入答案!"); }
}
int option = int.Parse(Console.ReadLine()); // 接受输入的参数
switch(option){
case 1:
case 2:
case 3: goto error;
case 4: goto right;
default :
Console.WriteLine("您选择的选项不存在!");
goto end;
}
right:
Console.WriteLine("恭喜你答对了");
end:
Console.ReadLine();
/*------------------------------------------------------------------------*/
Console.ReadKey();
}
static double avg (int a,int b,int c){
return (a+b+c)/3;
}
}
}
联系客服