本视频是解读性视频,所以希望您已经看过了本知识点的内容,并且编写了相应的代码之后,带着疑问来观看,这样收获才多。 不建议一开始就观看视频
13分21秒 本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项) 示例 1 : 基本算数操作符 示例 2 : 练习-求和 示例 3 : 答案-求和 示例 4 : 任意运算单元的长度超过int 示例 5 : 任意运算单元的长度小于int 示例 6 : %取模 示例 7 : 自增 自减 示例 8 : 自增 自减操作符置前以及置后的区别 示例 9 : 练习-自增 示例 10 : 答案-自增 示例 11 : 练习-BMI 示例 12 : 答案-BMI + - * / 基本的加 减 乘 除 public class HelloWorld {
public static void main(String[] args) {
int i = 10;
int j = 5;
int a = i+j;
int b = i - j;
int c = i*j;
int d = i /j;
}
}
public class HelloWorld { public static void main(String[] args) { int i = 10; int j = 5; int a = i+j; int b = i - j; int c = i*j; int d = i /j; } }
如果有任何运算单元的长度超过int,那么运算结果就按照最长的长度计算
比如 int a = 5; long b = 6; a+b -> 结果类型是long public class HelloWorld {
public static void main(String[] args) {
int a = 5;
long b = 6;
int c = (int) (a+b); //a+b的运算结果是long型,所以要进行强制转换
long d = a+b;
}
}
public class HelloWorld { public static void main(String[] args) { int a = 5; long b = 6; int c = (int) (a+b); //a+b的运算结果是long型,所以要进行强制转换 long d = a+b; } }
如果任何运算单元的长度都不超过int,那么运算结果就按照int来计算
byte a = 1; byte b= 2; a+b -> int 类型 public class HelloWorld {
public static void main(String[] args) {
byte a = 1;
byte b= 2;
byte c = (byte) (a+b); //虽然a b都是byte类型,但是运算结果是int类型,需要进行强制转换
int d = a+b;
}
}
public class HelloWorld { public static void main(String[] args) { byte a = 1; byte b= 2; byte c = (byte) (a+b); //虽然a b都是byte类型,但是运算结果是int类型,需要进行强制转换 int d = a+b; } }
% 取余数,又叫取模
5除以2,余1 public class HelloWorld {
public static void main(String[] args) {
int i = 5;
int j = 2;
System.out.println(i%j); //输出为1
}
}
public class HelloWorld { public static void main(String[] args) { int i = 5; int j = 2; System.out.println(i%j); //输出为1 } }
++
-- 在原来的基础上增加1或者减少1 public class HelloWorld {
public static void main(String[] args) {
int i = 5;
i++;
System.out.println(i);//输出为6
}
}
public class HelloWorld { public static void main(String[] args) { int i = 5; i++; System.out.println(i);//输出为6 } }
以++为例
int i = 5; i++; 先取值,再运算 ++i; 先运算,再取值 public class HelloWorld {
public static void main(String[] args) {
int i = 5;
System.out.println(i++); //输出5
System.out.println(i); //输出6
int j = 5;
System.out.println(++j); //输出6
System.out.println(j); //输出6
}
}
public class HelloWorld { public static void main(String[] args) { int i = 5; System.out.println(i++); //输出5 System.out.println(i); //输出6 int j = 5; System.out.println(++j); //输出6 System.out.println(j); //输出6 } } int i = 1; int j = ++i + i++ + ++i + ++i + i++; 问 j的结果是多少? 注: 先不要放在eclipse中,根据++置前 置后的理解自己先算一遍,然后再看答案
使用Scanner收集你的身高体重,并计算出你的BMI值是多少
BMI的计算公式是 体重(kg) / (身高*身高) 比如邱阳波的体重是72kg, 身高是1.69,那么这位同学的BMI就是 72 / (1.69*1.69) = ? 参考: 使用Scanner读取浮点数的办法
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|