Java Novice Note 3

Source: Internet
Author: User

1. Package

2. Operators

public class Operator {public static void main (string[] args) {int a = 5;       System.out.println ("a =" + a); A =-A;       +-System.out.println ("a =" + a);       + String link System.out.println ("Shadow shen" + "Software Development");       SYSTEM.OUT.PRINTLN (3 + 5 + "Software Development" + 6 + 8);       Double b = A/2;       System.out.println ("A/2 =" + (A/2));       System.out.println ("b =" + B);       int weith = 10;       int height = 6;       Double area = 1.0/2 * Weith * height;       System.out.println ("area =" + area);       int c = A% 3;//takes remainder System.out.println ("c =" + C); int d = c++;//C + + c = c + 1;       The first assignment after the increment int d = ++c;//The first increment after the assignment System.out.println ("D =" + D);       System.out.println ("c =" + C); Assignment int e = 10;       -= *=/=%= e + = 1;//E = e + 1;       System.out.println ("e =" + E);       Compare > >= 5 >= 5 5 > 5 < <= = = Boolean Isequals = (1 = = 1); System.out.println ("isequals =" + Isequals);       int year = 2012;        Boolean isleap = (year% 4 = = 0 && year%! = 0 | | year% 400 = = 0);       SYSTEM.OUT.PRINTLN (year + "Whether it is a leap year" + isleap);       SYSTEM.OUT.PRINTLN ("1! = 2?" + (1! = 2));       Logical Boolean isTrue = FALSE;       System.out.println ("isTrue" + isTrue);       System.out.println ("!istrue" +!istrue); System.out.println ("true | | False? "+ (True | |       false));//or Operation System.out.println ("True && false" + (True && false));//with operation int score = 85;  Score > 60 pass > 70 Good > 85 excellent//javase > && Oracle > + && XML > //javase > 60 | | Oracle > 60 | |       XML > int move = 16;         System.out.println ("move =" + (move >> 3)),//100 System.out.println ("move =" + (move << 1)); }}

 3. SELECT statement

Import java.util.random;//Classes public class Ifdemo {public static void main (string[] args) {Random ran = new Rand Om ();//new create object int score = Ran.nextint (101);//ran.nextint (41) + 60;//random number 0 ~ System.out.println ("score ="      + score);         /* IF (Score > 60) {//Meet the Conditional execution System.out.println ("============");         System.out.println ("passed..");      System.out.println ("============");         } *///if the second form */* if (Score > 60) {//satisfies the conditional execution System.out.println ("============");         System.out.println ("passed..");      System.out.println ("============");         } else {//does not meet the conditional execution System.out.println ("============");         System.out.println ("Very sorry ...");      System.out.println ("============");      }////Multiple branches match one of the conditions/* if (score >=) {System.out.println ("Score: A");      } else if (score >=/*&& score <) {System.out.println ("Score: B"); } else if (Score >=/*&& score < 80)      {System.out.println ("Score: C");      } else {System.out.println ("Score: D");        } */Switch (SCORE/10) {//If matching the code below executes case://system.out.println ("Score: A");        Case 9:system.out.println ("Score: A");        Case 8:system.out.println ("Score: B");        Case 7:system.out.println ("Score: C");        Case 6:system.out.println ("Score: D");      Default:System.out.println ("Score: Failed");      }//Three mesh operator Boolean ispass = (Score > True:false);      System.out.println ("score = = =" + Ispass); String passed = score > 60?      "Pass": "Hang Up";         System.out.println ("achievement = = =" + passed); }}

4.while Cycle

Import Java.util.random;public class Loopdemo {public     static void Main (string[] args) {              int i = 0;//counter       //loop c3/> does not satisfy the condition that execution   may execute 0 times       (i <) {               System.out.println (i + "Hello World!...");//execute code          i++;//Runtime The I value changes every time I = Ten       }               System.out.println ("i =" + i);       i = 0; 0  9       do{//perform a  System.out.println at least once          (i + "Happy!...");          i++;       }       while (I < ten);              int a = Ran.nextint (101);       System.out.println ("a =" + a);       int i = 2;       while (I < a) {//67          if (a% i = = 0) {             break;//jump out of Loop          }          i++;       }       System.out.println ("i =" + i);       if (i >= a)//normal exit cycle          System.out.println (A + "is prime");       else          System.out.println (A + "not Prime");}    }

5.for Cycle

Import Java.util.random;public class LoopDemo2 {public     static void Main (string[] args) {      int k = 10;//variable scope in method Use      //i local variable for            (int i = 0;i < i++) in method {//Three statement         System.out.println (i + "Hello World!...");               }            //Loop nesting/      * for      (int i = 0; i < 5; i++) {         //k = k + i;         for (int j = 0; J < 3; J + +) {            System.out.print ("*");         }         System.out.print ("\ n");//Output Wrap      } */For      (int i = 1; i < 6; i++) {for         (int j = 1; J <= I; j + +) {
   system.out.print (j + "*" + i + "=" + I * j + "  ");         }         System.out.print ("\ n");      }           int sum = 0;      int i;      for (i = 1; i < i++) {         sum + = i;         if (sum >=) {break            ;         }            }      System.out.println ("sum =" + sum);      System.out.println ("i =" + i);}    }

6. Marking Loops

Import Java.util.random;public class LoopDemo3 {public     static void Main (string[] args) {           int sum = 0;      int i,k =-1;      Loopi:for (i = 1; i <; i++) {for         (int j = 1; j < K; J + +) {            sum + = j;            if (sum >=) {                k = j;               Break loopi;//Specifies the bounce position            }                     }         System.out.println ("k =" + K);         System.out.println ("i =" + i);      }      System.out.println ("sum =" + sum);      System.out.println ("k =" + K);      for (int a = 1; a < 101; a++) {         if (a% 3! = 0) {//cannot be divisible by 3              continue;//ends this time after code execution         }         System.out.print ( A + "\ T");}}}          

7. Double Cycle

public class LoopDemo4 {public     static void Main (string[] args) {           int sum = 0;            for (int i = 1; i < one; i++) {//control is line for         (int j = 1; J <= I; j + +) {//Control column            System.out.print ("*");            /**/            if (J > 5) {//1 2 3 4 5 6   7 8 9                          break;//jump out of inner loop            }                       }                  System.out.println ();          }}

Java Novice Note 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.