.net 基础

1、  说出以下代码的运行结果,并分析:

public static void Main(String[] args) {

        int a = 0;

        int b = 2;

        int c = 4;

        a += b += c += 6;  

        System.Console.WriteLine("c="+c);

        System.Console.WriteLine("b="+b);

        System.Console.WriteLine("a="+a);

    }

2 public static void Main(String[] args) {

           int a = 2;

              if( a%2 == 0 ? false : true ){

                     System.Console.WriteLine("学习");

              }else{

                     System.Console.WriteLine("不学习");   

              }

    }

 

 3  public static void Main(String[] args) {

           int a = 2;

              if( a++ > 2 && ++a > 2 ){   

  }

       if( a++ < 2 || ++a > 2){ 

              }

              System.Console.WriteLine("a="+a); //a=5   

    }

   4    public static void Main(String[] args) {

          outer:for (int i = 0; i < 5; i++) {

                     for (int j = i; j < 5; j++) {

                            System.Console.Write("-");

                            goto outer;                    }

                     System.Console.Write("\r\n"); 

              }

       }

5 public static void Main(String[] args) {

           bool flag = true;

              for (int i = 0; i < 5 && flag; i++) {

                     for (int j = i; j < 5; j++) {

                            System.Console.Write("-");

                            flag = false ;

                     break;

                     }

                     System.Console.Write("\r\n");             }

  }

       

6 public static void Main(String[] args) {

                  int i;

                  int j;

                     for(i=0,j=5; i < j; i++,j--){

                            System.Console.WriteLine("i="+i); }

                     System.Console.WriteLine("结束后i="+i);

                     System.Console.WriteLine("结束后j="+j);  

       }

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。