22nd Java Some of the keywords, scopes and the use of operators

Source: Internet
Author: User

Hello, I come to share with you some of the knowledge I have learned today, today I learned how to use some of the keywords in Java, the use of job fields and operators ....

First of all, what are the keywords in Java, because there are a lot of them, I'll take a look at the key words I learned today:

The first keyword I learned was----Scanner, who represented the scanner in Java, and introduced the package, and his role was to monitor the input of the keyboard, the most frequently seen in the registration or login interface, which is to use the value you entered, and take it out,

The second keyword is-------return, he is the expression of the return value, as for his specific role, I still have some do not understand, so here is not detailed introduction.

Here's a look at what the scope is, and just use the example to illustrate it:

public class Test {

public static void Main (String [] args) {

int x=1;

{int y = 2;

System.out.println (x, y);

}

System.out.println (x, y);

}

}

wherein, the red font represents the scope, his scope of access is only in the current code block, more than can not, cannot find the file, so the following sentence output statement basically will be an error is this reason;

As for the use of operators, here I will say two more, operators are divided into many kinds, there are arithmetic operators, relational operators, and logical operators

Relational operators (included): > < = >= <= = = =! =

logical operators (including):! ----inverse, the variable is true, the value is false, the variable is false, the value is true;

&&-----and true at the same time, value is true

|| ------Or, one is true, the value is True

Arithmetic operators (including): +-*/%--+ +


As for their role, I am not in one by one explained, I give a very simple game, I bring you a very simple Java program written---landing interface:

The code is as follows:


Import Java.util.Scanner;


public class lei{
public static void Main (String [] args) {

Scanner sc=new Scanner (system.in);


System.out.println ("Please enter user name:");
String Person_name=sc.nextline ();

System.out.println ("Please enter password:");
String Password=sc.nextline ();

if ("a". Equals (Person_name) && "AA". Equals (password)) {
SYSTEM.OUT.PRINTLN ("User login Success");
}else if ("". Equals (person_name) | | "". Equals (password)) {
System.out.println ("User name and password cannot be empty")
}else{
System.out.println ("User name or password is wrong, please re-enter");
}


}

}

Well, try it yourself.

Because of the relationship of time, write here today, and now continue to remind each day of their goals and plans:

1, daily exercise fingering an hour;

2, every day to write a blog or log, used to record the life of a bit;

3, every day class insisted 15 minutes advance into the classroom;

4, every day to give themselves to paragraph encouragement of words--------not to do the giant, action on the dwarf, so dream is always just a dream;



















22nd Java Some of the keywords, scopes and the use of operators

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.