0 Fundamentals of Android Development Java language Learning 02-Basic syntax

Source: Internet
Author: User

The first Java program

Here's a simple Java program that will print the string Hello World

Com.henancaiyun package, mainly used to solve the same name problem. Each class must be specified under a package.
Package Com.henancaiyun;

Import ClassA
Import Com.henancaiyun.ClassA;

Helloword class
public class Helloword {

Main static function
public static void Main (string[] args)
{
/* This is the first Java program
* It will print Hello World
* This is an example of a multiline comment
*/
String variable Helloword
String helloword= "Hello Word";
System output Hello Word character
System.out.println (Helloword);

}

}

------------------------------------------------------------------------------------------

Com.henancaiyun package, mainly used to solve the same name problem. Each class must be specified under a package.
Package Com.henancaiyun;

Import Java.sql.Date;

Helloword class
public class Helloword {


Main static function
public static void Main (string[] args)
{
/* This is the first Java program
* It will print Hello World
* This is an example of a multiline comment
*/
String variable Helloword
String helloword= "Hello Word";

System output Hello Word character
System.out.println (Helloword);

Checkstudey ();

}

Data type
public static void Datatypestudey ()
{
BYTE h=10;
Short i=20;
int j=30;
Long k=30;
float l=0.000000000000000000000000000000000000000000001f;
Double m=0.0000000000000000000000000000000000000000000000000000000000000000000000000001;
Boolean flag=true;
Char c= ' 1 ';
String str= "I am Li bao Qing";
int [] intarray=new int []{1,2,3,4,5};
intarray[0]=0;
string [] strarray=new string []{"1", "2", "3"};
System.out.println (Intarray[0]);

 }
 //variable
 public static void Veriablestudey ()
 {
  int a=1;
 
  final int b=10;
  
  a=10;
  a=11;
  
  system.out.println (a);
  
 }
 
    //operator
  public static void Computechatstudy ()
  {
   /* arithmetic operator
   + Add-add operator on both sides of the value A + B equals $
   -subtraction-The left operand minus the right operand a–b equals -10
   * multiplication-the value on either side of the multiply operator is a * b equals a number
   /except Law-left operand divided by right operand b/a equals 2
   % modulo-left operand except right operand remainder b%a equals 0
   + + self increment-operand value increases 1 B + + equals 21
   ----the value of the operand is reduced by 1 B--equals
   */
   int a=1;
   int b=2;
   int c=a+b;
   c++;
   
   system.out.println (c);


/* Relational operators
* = Check if the values of the two operands are equal, the condition is true if they are equal. (A = = B) is False (not true).
! = Checks if the values of the two operands are equal, and the condition is true if the values are not equal. (A! = B) is true.
> Checks if the value of the left operand is greater than the value of the right operand, and if so the condition is true. (a> B) not true.
< checks if the value of the left operand is less than the value of the right operand, and if so the condition is true. (A <b) is true.
> = checks whether the value of the left operand is greater than or equal to the value of the right operand, and if so the condition is true. (a> = B) is false.
<= checks if the value of the left operand is less than or equal to the value of the right operand, and if so the condition is true. (a <= B) is true.
*/


Boolean flag= (A==B);

SYSTEM.OUT.PRINTLN (flag);

/* Logical operator
&& is called logic and operator. The condition is true when and only if two operands are true. (A && B) are false.
| | Called a logical OR operator. If any one of the two operands is true, the condition is true. (A | | B) is true.
! is called a logical non-operator. The logical state used to reverse the operand. If the condition is true, the logical non-operator will get false.
*/
Boolean flag2= (A==b&&b==c);

SYSTEM.OUT.PRINTLN (flag);

/* Assignment operator
= Simple assignment operator, assigning the value of the right operand to the left operand C = A + B assigns the value obtained by A + B to c
+ = Plus and assignment operator, which adds the left operand and the right operand to the left operand C + = a equivalent to C = C + A
-= minus and assignment operator, which subtracts the left and right operands from the left operand c-= A is equivalent to C = c-a
* = Multiply and assign operators, which multiply the left and right operands by assigning A value to the left operand c * = a equivalent to C = c * A
/= In addition to and assignment operators, it assigns the left operand and the right operand to the left operand c/= A equivalent to C = c/a
* */
int h=0;
h+=2;//(h=h+2)
SYSTEM.OUT.PRINTLN (flag);
/* Conditional operator
* The conditional operator is also known as the ternary operator. The operator has 3 operands and needs to determine the value of a Boolean expression. The main decision of the operator is to decide which value should be assigned to the variable.
* */
int i= (h==0?1:0);
String name= (h==0? " LBQ ":" Lxq ");
SYSTEM.OUT.PRINTLN (flag);

}
Looping statements
public static void Circlestudey ()
{
While loop
int x = 10;
while (x < 20) {
System.out.print ("While loop of x:" + x);
x + +;
System.out.print ("\ n");
}

Do...while Cycle
x = 10;
do{
System.out.print ("Do...while cycle x:" + x);
x + +;
System.out.print ("\ n");
}while (x < 20);

For loop
for (int i = ten; i <; i = x+1) {

if (i==10)
Continue
if (i==12)
Break
System.out.print ("For Loop of x:" + i);
System.out.print ("\ n");
}

}

Judgment statement
public static void Checkstudey ()
{
int x = 10;
If statement
if (x < 20) {
System.out.print ("This is an if statement");
}
If...else statements
if (x < 20) {
System.out.print ("This is an if statement");
}else{
System.out.print ("This is the Else statement");
}
If...else if...else Statements
if (x = = 10) {
System.out.print ("Value of X is 10");
}else if (x = = 20) {
System.out.print ("Value of X is 20");
}else if (x = = 30) {
System.out.print ("Value of X is 30");
}else{
System.out.print ("This is Else statement");
}
Switch statement
Char grade = ' B ';

Switch (grade)
{
Case ' A ':
System.out.println ("excellent!");
Break
Case ' B ':
Case ' C ':
System.out.println ("Well-done");
Break
Case ' D ':
SYSTEM.OUT.PRINTLN ("You passed");
Case ' F ':
System.out.println ("Better try Again");
Break
Default:
System.out.println ("Invalid grade");
}
System.out.println ("Your grade is" + grade);

  }
    
    //Method Learning
     public static void Method ()
     {
      int a=1;
      int b=2;
      int Maxvalue=max (A, b);
      
      system.out.println (maxValue);
    
    
    /** Returns a larger value for two integer variable data */
      public static int max (int num1, int num2) {
        int result;
        if (Num1 > Num2)
           result = NUM1;
        Else
           result = num2;

return result;
}

/*
public static void Classstudey ()
{
A dog.
Dog Hashishiqi=new Dog ();
Hashishiqi.breed= "Hashiqi";
hashishiqi.age=1;
Hashishiqi.color= "Gray";
Another dog.
Dog Muyangquan=new Dog ();
Muyangquan.breed= "Hashiqi";
muyangquan.age=1;
Muyangquan.color= "Gray";

}
*/

}

0 Fundamentals of Android Development Java language Learning 02-Basic syntax

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.