unity3D-游戏/AR/VR在线就业班 C#入门If 语句学习笔记

unity3D-游戏/AR/VR在线就业班 C#入门If 语句学习笔记

http://edu.csdn.NET/lecturer/107

一、if(条件表达式){语句1}

using System;

namespace Lesson11
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            //顺序结构
//            int a =4;
//            int b = a * 2 + 16;
//            Console.WriteLine (b);

            int i = 0;
            i = int.Parse(Console.ReadLine ());
            // 条件表达式值是true,就会执行后面代码块的代码,否则不会执行

            if(i %2==0)
            {
                Console.WriteLine ("输入的数是偶数");
        
            }
            Console.WriteLine ("[Over]x");

    
        }
    }
}


二、if(条件表达式){语句1;} else{语句2;}

 

using System;

namespace Lesson11
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            //顺序结构
//            int a =4;
//            int b = a * 2 + 16;
//            Console.WriteLine (b);

            int i = 0;
            i = int.Parse(Console.ReadLine ());
            // 条件表达式值是true,就会执行后面代码块的代码,否则不会执行
            //一、if(条件表达式){语句1}
//            if(i %2==0)
//            {
//                Console.WriteLine ("输入的数是偶数");
//            }
//            Console.WriteLine ("[Over]");

            //二、if(条件表达式){语句1;} else{语句2;}
            if (i % 2 == 0) {
                
                Console.WriteLine ("输入的数是偶数");
            } else {
                Console.WriteLine ("奇数");
            }
            Console.WriteLine ("[Over]");
        }
    }
}

三、if(条件表达式1){语句1;} else if(条件表达式2){语句2;}else{语句3}

 

            //三、if(条件表达式1){语句1;} else if(条件表达式2){语句2;}else{语句3}
            int i = int.Parse(Console.ReadLine ());

            if (i < 0) {
                Console.WriteLine ("负数");
            } else if (i >= 0 && i < 10) {
                Console.WriteLine ("一位数");
            } else if (i >= 10 && i < 100) {
                Console.WriteLine ("两位数");
            } else {
                Console.WriteLine ("你输入的数太大了,崩~");
            } 
 
            int money = int.Parse (Console.ReadLine ());
            string str = "";
            if (money >= 100) {
                str = "买买买~";    
            } else {
                str = "回家吃土";
            }
            Console.WriteLine (str); 
  


四、问号表达式 条件表达式?表达式1:表达式2

 

  

//问号表达
            int money = int.Parse (Console.ReadLine ());
            string str = ""; 

            str =(money>=100)?"买买买~":"回家吃土";
            Console.WriteLine (str); 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值