复合赋值运算符:
运算符 |
用法 |
等价形式 |
+= |
op1+=op2 |
op1=op1+op2 |
-= |
op1-=op2 |
op1=op1-op2 |
/= |
op1/=op2 |
op1=op1/op2 |
%= |
op1%=op2 |
op1=op1%op2 |
*= |
op1*=op2 |
op1=op1*op2 |
在有些地方会出现:
op1=+op2 此处的运算符=+实际上是将op2进行一元运算。
下面的例子为:
public class BasicExample {
public static void main(String[] args) {
int total=0;
for(int i=1;i<=3;i++){
total=+i;
System.out.println("Sum="+total);
}
char c='c';
total=+c;
System.out.println("Sum="+total);
}
}
outprintln:
Sum=1
Sum=2
Sum=3
Sum=99
扩展:其他运算符;
1: ?: 运算符 op1?op2:op3 改运算符在op1为true的时候返回op2,否者返回op3;
2: 【】 运算符 float [] arrayOfFloats =new float[10]; or float arrayOfFloats[] =new float[10];
3: . 运算符 用来访问对象实例或访问类的成员变量或成员方法;
4: () 运算符 用于放参数
5: (type) 运算符 将某类型的值或对象转换为type型
6: new
7:instanceof op1 instanceof op2 op1为对象名 op2为类名
分享到:
相关推荐
Idiot‘s_Guides_to_Beginning_Programming.pdf
An Idiot's Guide to C++ Templates
Idiot
The Complete Idiot’s Guide to iPad and iPhone App Development .pdf
The Complete Idiot's Guide to Improving Your IQ.pdf
傻瓜指南系列-如何作小生意]The.Complete.Idiot's.Guide.-.Small.Business.pdf
Explorer扩展编程的指导资料,包括一个chm教程以及其对应的源代码。 Part I - A step-by-step tutorial on writing shell extensions Part II - A tutorial on writing a shell extension that operates on ...
概述 Jnario是用于编写Java可执行规范的框架。 它提供了Xtend的所有优势,同时专门为编写验收和单元测试而量身定制。 当Jnario规范被编译为普通Java Junit测试时,很容易集成。... As a math idiot I want to be told
idiot
An Idiot’s guide to Support vector machines (SVMs)
详细说明Windows Shell的编程指南,可以处理Windows Explorer资源管理器很多的交互,比如文件复制和剪切,鼠标右键菜单的添加,任意文件的图标的修改和叠加,系统文件拷贝进度条的控制...由大牛Idiot整理,有完整的源码
加密已有文件,可以临时加密和永久解密;加密特定文件夹
This guide helps environmentally conscious people make real-world ...·More than 80 regional and local green building programs are in place in the U.S. and more are being promoted in the private sector
HTML Reference for dummies, idiot, beginner
most simple adding for those idiot
CSS 2 Reference for begginer, idiot, dummies
American Idiot is the seventh studio album by American rock band Green Day
笨蛋 物联网ID
这是关于Java基础的入门教程,主要是数据结构,txt版的