当前位置:网站首页>Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
2022-07-02 12:50:00 【Onycho】
Operator
Self increasing , Self reduction
package operator;
public class Demo04 {
public static void main(String[] args) {
//++ -- Self increasing , Self reduction Unary operator
int a= 3;
int b = a++; // After executing this line of code , First give b assignment , Since the increase again
// a = a+1
System.out.println(a);
// a = a+1;
int c = ++a; // Before this line of code is executed , First of all, increase by yourself , Give again b assignment
System.out.println(a);
System.out.println(b);
System.out.println(c);
// Power operation 2*3 2*2*2 = 8 Many operations are operated by tool classes !
double pow = Math.pow(2,3);
System.out.println(pow);
}
}
Output
4
5
3
5
8.0
Logical operators
package operator;
// Logical operators
public class Demo05 {
public static void main(String[] args) {
// And (and) or (or) Not ( Take the opposite )
boolean a = true;
boolean b = false;
System.out.println("a && b:"+(a && b)); // Logic and computation : Both variables are true , The result is true
System.out.println("a || b:"+(a||b)); // Logic or operation : One of the two variables is true , The result is true
System.out.println("! (a && b):"+!(a&&b)); // If it is true , It becomes false , If it is false, it becomes true
// Short-circuit operation
int c = 5;
boolean d = (c<4)&&(c++<4);
System.out.println(d);
System.out.println(c);
Output
a && b:false
a || b:true
! (a && b):true
false
5
An operation
package operator;
// An operation
public class Demo06 {
public static void main(String[] args) {
/* A = 0011 1100 B = 0000 1101 A&B = 0000 1100(“ And ” all 1 by 1) A|B = 0011 1101(“ or ” There is one 1 Then for 1) A^C =0011 0001(“ Exclusive or ” Same as 0, Different for 1) ~B = 1111 0010(“ Take the opposite ” The opposite ) 2*8 = 16 2*2*2*2 Very efficient << Move left *2 >> Move right /2, When the arrow points that way, it's called moving 0000 0000 0 0000 0001 1 0000 0010 2 0000 0011 3 0000 0100 4 0000 1000 8 0001 0000 16 */
System.out.println(2<<3);
}
}
Output
16
Binary to decimal
0000 0000 0 Binary default 0
0000 0001 1 From left to right 0~7, be 2^0 = 1
0000 0010 2 2^1 = 2
0000 0011 3 2^1 + 2^0 = 3
0000 0100 4 2^2 = 4
0000 1000 8 2^3 = 8
0001 0000 16 2^4 =16
String connector +
package operator;
public class Demo07 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a += b; //a = a + b
a -= b; //a = a - b
// String connector + , String
System.out.println(a + b);
System.out.println("" + a + b); // String before , The back will be spliced
System.out.println(a + b + ""); // String after , The front can calculate
}
}
Output
30
1020
30
Ternary operator
package operator;
// Ternary operator
public class Demo08 {
public static void main(String[] args) {
// x ? y : z
// If x == true, The result is y, Otherwise z
int score = 80;
String type = score < 60 ?" fail, ":" pass ";
// if
System.out.println(type);
}
}
Output
pass
Packet mechanism
Pay attention to Idea Created in com.baidu When a child package cannot be created automatically
Click the pinion at the top right of the project structure on the left ,
Uncheck the compact middle packlages Options , At this point you build a com.itheima.package package ,
It will be shown as com It's a bag itheima package ,itheima It's a bag package.java!
import com.jiao.*; // Import all classes under this package
Documentation Comments
package com.jiao.base;
/** * @author John * @version 1.0 * @since 1.8 */
public class Doc {
String name;
/** * @param name * @return * @throws Exception */
public String test(String name)throws Exception {
return name;
}
}
doc Order sample
javadoc -encoding UTF-8 -charset UTF-8 Doc.java
边栏推荐
- Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
- JSON序列化 与 解析
- 8A Synchronous Step-Down regulator tps568230rjer_ Specification information
- ArrayList与LinkedList效率的对比
- Linear DP acwing 899 Edit distance
- 获取文件版权信息
- C modifier
- [FFH] little bear driver calling process (take calling LED light driver as an example)
- Shutter encapsulated button
- Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
猜你喜欢
堆 AcWing 838. 堆排序
Interesting interview questions
染色法判定二分图 AcWing 860. 染色法判定二分图
Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
[ybtoj advanced training guidance] judgment overflow [error]
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
线性DP AcWing 899. 编辑距离
堆 AcWing 839. 模拟堆
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
VLAN experiment
随机推荐
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
线性DP AcWing 896. 最长上升子序列 II
Some sudden program ideas (modular processing)
软件测试面试题-2022年大厂面试题合集
JS iterator generator asynchronous code processing promise+ generator - > await/async
Get started REPORT | today, talk about the microservice architecture currently used by Tencent
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
架构师必须了解的 5 种最佳软件架构模式
3 a VTT terminal regulator ncp51200mntxg data
Hundreds of web page special effects can be used. Don't you come and have a look?
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
spfa AcWing 851. SPFA finding the shortest path
Linear DP acwing 897 Longest common subsequence
哈希表 AcWing 841. 字符串哈希
Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
Mobile layout (flow layout)
染色法判定二分图 AcWing 860. 染色法判定二分图
堆 AcWing 839. 模拟堆
C operator