- 博客(19)
- 收藏
- 关注
原创 switch语句(多值判断)
/** 测试switch多选择结构 遇到多值判断的时候,使用switch,当然,switch完全可以使用ifelseifelse代替! @author 王绍乾 */ public class switch多选择结构 { public static void main(String[] args) { int month = (int) (1 + 12 * Math.random()); System.out.println(“月份:” + month); switch (month) {
2020-07-11 09:51:01
2068
原创 If所有类型结构
一. /** 测试if单选择结构 @author 王绍乾 */ public class TestIF { public static void main(String[] args) { double d = Math.random();//返回【0,1) System.out.println(d); int h = (int) (6 * Math.random() + 1); ...
2020-02-25 16:43:56
281
原创 使用Scanner获取键盘输入
import java.util.Scanner;//导入Scanner包 /** 使用Scanner获取键盘输入 @author 王绍乾 / public class TestScanner { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.prin...
2020-02-02 13:20:42
211
原创 基本类型常见错误
/** 测试类型转化常见问题 @author 王绍乾 / //溢出问题 public class TestOperator09 { public static void main(String[] args) { int money = 1000000000;//10亿 int years = 20; int total01 = moneyyears; System.out.println(...
2020-02-02 12:45:50
211
原创 强制类型转换
/** 强制类型转换 @author 王绍乾 */ public class TestOperator08 { public static void main(String[] args) { double x = 3.14; int nx = (int)x; char c =‘a’; int d = c+1; System.out.println(nx); System.out.prin...
2020-02-01 13:32:37
162
原创 自动类型转换
/** *自动类型转换 @author 王绍乾 由容量小向容量大的转化 */ public class TestOperator07 { public static void main(String[] args) { int a = 324; long b =a; double d =b; //特例 byte b2=123; } } ...
2020-02-01 13:17:30
166
原创 运算符种类及其讲解
一. public class TestOperator1 { public static void main(String[] args) { byte a = 1; int b = 2; // byte c =a+b;//报错:a+b为int类型,不能赋给byte int c1 =a+b; long b2 = 3; //int c2 = b2+b;//报错:数据是long类型,不能赋给in...
2020-01-30 15:32:15
282
原创 布尔型测试(if语句)
/** *测试布尔型(if语句) @王绍乾 */ public class TestPrimitiveDateType3 { public static void main(String[] args) { boolean man = false; if (man) { System.out.println("男性"); }else{ Sy...
2019-12-30 23:22:06
2207
原创 字符型类型&转义字符
/** *测试字符类型 @王绍乾 */ public class TestPrimitiveDateType2 { public static void main(String[] args) { char a = ‘F’; char b = ‘王’; char c = ‘\u0061’; System.out.println©; //转义字符 System.out.pr...
2019-12-29 23:39:58
298
原创 浮点型变量和Bigdecimal的使用
import java.math.BigDecimal; public class TestPrimitiveDateType { public static void main(String[] args) { float a =0.1f; double b= 1.0/10; double c =628E-2; System.out.println(b==a);//结果为false,f...
2019-12-29 22:24:27
179
原创 第一次编译(用Java输出Hello World)及错误总结
public class Welcome { public static void main(String[] argg) { System. out. println("Hello World"); } } 1.注意单词的拼写并注意大小写 2.注意该空格的地方就空格 3.符号必须为英文的 ...
2019-11-21 21:48:40
406
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅