首页
学习笔记
Linux笔记
主题美化
电脑小技巧
Java笔记
资源素材
软件工具
网站素材
电子书
友情链接
留言板
更多
关于
搜索
登录
1
网站实现樱花飘落效果
605 阅读
2
Typecho主题
564 阅读
3
typecho相册单页模板
485 阅读
4
PotPlayer v1.7.21759绿色版
475 阅读
5
硬盘U盘去掉写保护
432 阅读
Search
标签搜索
JS
美化
linux
工具
Windows
Typecho
Java
命令
模板
下载
电脑
驱动
插件
主题
播放器
源码
优化
笔记
国庆头像
奇妙的Linux
累计撰写
28
篇文章
累计收到
22
条评论
首页
栏目
学习笔记
Linux笔记
主题美化
电脑小技巧
Java笔记
资源素材
软件工具
网站素材
页面
电子书
友情链接
留言板
关于
管理后台
搜索到
3
篇与
相关的结果
2023-07-13
Java初学-流程控制语句
条件语句-if...else 语法 if(布尔表达式){ //布尔值=true,执行语句 }else{ ////布尔值=falese,执行语句 }代码练习 if...else语句 piblic class Test{ public static void main(String args[]){ int a = 10; if(a>20){ System.out.println("a>20"); }else{ System.out.println("a<20"); } } } if...else if...else语句 public class Test { public static void main(String args[]){ int a = 30; if( a == 10 ){ System.out.println("结果是:10"); }else if( a == 20 ){ System.out.println("结果是:20"); }else if( a == 30 ){ System.out.println("结果是:30"); }else{ System.out.println("都不是"); } } }{dotted startColor="#ff6c6c" endColor="#1989fa"/}for循环 语法 for(int i =0; i<100;i++){ //循环做的事情 }代码练习 for循环-打印数字1-5 public class Test { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { System.out.println(i); } } } for循环嵌套-打印99乘法表 public class Main { public static void main(String[] args) { //打印99乘法表 for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { System.out.print(i+""+"*"+j+"="+j*j+" " ); } System.out.println(""); } } }
2023年07月13日
149 阅读
0 评论
2 点赞
2023-07-13
Java初学-运算符
算术运算符算术运算符用在数学表达式中,它们的作用和在数学中的作用一样。下表列出了所有的算术运算符。操作符描述例子+相加-左右两边的值相加int a = b + c;-相减-左边的值减右边的值int a = b - c;*乘法-左右两边的值相乘int a = b * c;/除法-左边的值除以右边的值int a = b / c;%取余-左边的值除以右边的值的余数int a = b % c;++自增-操作数的值增加1i++;/++i;--自减-操作数的值减少1i--;/++i;代码练习public class Demo { public static void main(String[] args) { int a = 0; int b =10; int c= 3; System.out.println(a = b + c); //13 System.out.println(a = b - c); //7 System.out.println(a = b * c); //30 System.out.println(a = b / c); //3 System.out.println(a = b % c); //1 System.out.println(--c); //2 System.out.println(++b); //11 } } {dotted startColor="#ff6c6c" endColor="#1989fa"/}关系运算符下表为Java支持的关系运算符运算符描述例子==检查如果两个操作数的值是否相等,如果相等则条件为真。(A == B)为假。!=检查如果两个操作数的值是否相等,如果值不相等则条件为真。(A != B) 为真。>检查左操作数的值是否大于右操作数的值,如果是那么条件为真。(A> B)为假。<检查左操作数的值是否小于右操作数的值,如果是那么条件为真。(A <B)为真。>=检查左操作数的值是否大于或等于右操作数的值,如果是那么条件为真。(A> = B)为假。<=检查左操作数的值是否小于或等于右操作数的值,如果是那么条件为真。(A <= B)为真。代码练习public class Demo { public static void main(String[] args) { int a = 10; int b = 20; System.out.println("a == b = " + (a == b) ); System.out.println("a != b = " + (a != b) ); System.out.println("a > b = " + (a > b) ); System.out.println("a < b = " + (a < b) ); System.out.println("b >= a = " + (b >= a) ); System.out.println("b <= a = " + (b <= a) ); } }{dotted startColor="#ff6c6c" endColor="#1989fa"/}位运算符下表列出了位运算符的基本运算,假设整数变量 A 的值为 60 和变量 B 的值为 13:操作符描述例子&如果相对应位都是1,则结果为1,否则为0(A&B),得到12,即0000 1100|如果相对应位都是 0,则结果为 0,否则为 1(A | B)得到61,即 0011 1101^如果相对应位值相同,则结果为0,否则为1(A ^ B)得到49,即 0011 0001〜按位取反运算符翻转操作数的每一位,即0变成1,1变成0。(〜A)得到-61,即1100 0011<<按位左移运算符。左操作数按位左移右操作数指定的位数。A << 2得到240,即 1111 0000>>按位右移运算符。左操作数按位右移右操作数指定的位数。A >> 2得到15即 1111>>>按位右移补零操作符。左操作数的值按右操作数指定的位数右移,移动得到的空位以零填充。A>>>2得到15即0000 1111代码练习public class Test { public static void main(String[] args) { int a = 60; /* 60 = 0011 1100 */ int b = 13; /* 13 = 0000 1101 */ int c = 0; c = a & b; /* 12 = 0000 1100 */ System.out.println("a & b = " + c ); c = a | b; /* 61 = 0011 1101 */ System.out.println("a | b = " + c ); c = a ^ b; /* 49 = 0011 0001 */ System.out.println("a ^ b = " + c ); c = ~a; /*-61 = 1100 0011 */ System.out.println("~a = " + c ); c = a << 2; /* 240 = 1111 0000 */ System.out.println("a << 2 = " + c ); c = a >> 2; /* 15 = 1111 */ System.out.println("a >> 2 = " + c ); c = a >>> 2; /* 15 = 0000 1111 */ System.out.println("a >>> 2 = " + c ); } }{dotted startColor="#ff6c6c" endColor="#1989fa"/}逻辑运算符下表列出了逻辑运算符的基本运算,假设布尔变量A为真,变量B为假操作符描述例子&&称为逻辑与运算符。当且仅当两个操作数都为真,条件才为真。(A && B)为假。||称为逻辑或操作符。如果任何两个操作数任何一个为真,条件为真。(A || B)为真。!称为逻辑非运算符。用来反转操作数的逻辑状态。如果条件为true,则逻辑非运算符将得到false。!(A && B)为真。代码练习public class Test { public static void main(String[] args) { boolean a = true; boolean b = false; System.out.println("a && b = " + (a&&b)); System.out.println("a || b = " + (a||b) ); System.out.println("!(a && b) = " + !(a && b)); } }{dotted startColor="#ff6c6c" endColor="#1989fa"/}赋值运算符下面是Java语言支持的赋值运算符:操作符描述例子=简单的赋值运算符,将右操作数的值赋给左侧操作数C = A + B将把A + B得到的值赋给C+ =加和赋值操作符,它把左操作数和右操作数相加赋值给左操作数C + = A等价于C = C + A- =减和赋值操作符,它把左操作数和右操作数相减赋值给左操作数C - = A等价于C = C - A* =乘和赋值操作符,它把左操作数和右操作数相乘赋值给左操作数C = A等价于C = C A/ =除和赋值操作符,它把左操作数和右操作数相除赋值给左操作数C / = A,C 与 A 同类型时等价于 C = C / A%=取模和赋值操作符,它把左操作数和右操作数取模后赋值给左操作数C%= A等价于C = C%A<< =左移位赋值运算符C << = 2等价于C = C << 2>> =右移位赋值运算符C >> = 2等价于C = C >> 2&=按位与赋值运算符C&= 2等价于C = C&2^ =按位异或赋值操作符C ^ = 2等价于C = C ^ 2| =按位或赋值操作符C | = 2等价于C = C | 2代码练习 int a = 10; int b = 20; int c = 0; c = a + b; System.out.println("c = a + b = " + c ); c += a ; System.out.println("c += a = " + c ); c -= a ; System.out.println("c -= a = " + c ); c *= a ; System.out.println("c *= a = " + c ); a = 10; c = 15; c /= a ; System.out.println("c /= a = " + c ); a = 10; c = 15; c %= a ; System.out.println("c %= a = " + c ); c <<= 2 ; System.out.println("c <<= 2 = " + c ); c >>= 2 ; System.out.println("c >>= 2 = " + c ); c >>= 2 ; System.out.println("c >>= 2 = " + c ); c &= a ; System.out.println("c &= a = " + c ); c ^= a ; System.out.println("c ^= a = " + c ); c |= a ; System.out.println("c |= a = " + c ); } }{dotted startColor="#ff6c6c" endColor="#1989fa"/}三元运算符该运算符有3个操作数,并且需要判断布尔表达式的值。该运算符的主要是决定哪个值应该赋值给变量。variable x = (expression) ? value if true : value if false代码练习public class Test { public static void main(String[] args){ int a , b; a = 10; // 如果 a 等于 1 成立,则设置 b 为 20,否则为 30 b = (a == 1) ? 20 : 30; System.out.println( "Value of b is : " + b ); // 如果 a 等于 10 成立,则设置 b 为 20,否则为 30 b = (a == 10) ? 20 : 30; System.out.println( "Value of b is : " + b ); } }{dotted startColor="#ff6c6c" endColor="#1989fa"/}
2023年07月13日
138 阅读
0 评论
1 点赞
2023-07-13
Java初学-HelloWord
常用IDEIntelliJ IDEAEclipse基本数据类型{dotted startColor="#ff6c6c" endColor="#1989fa"/}byte{callout color="#f0ad4e"}byte 数据类型是8位、有符号的,以二进制补码表示的整数;最小值是 -128(-2^7);最大值是 127(2^7-1);默认值是 0;byte 类型用在大型数组中节约空间,主要代替整数,因为 byte 变量占用的空间只有 int 类型的四分之一;例子:byte a = 100;{/callout}short{callout color="#f0ad4e"}short 数据类型是 16 位、有符号的以二进制补码表示的整数最小值是 -32768(-2^15);最大值是 32767(2^15 - 1);Short 数据类型也可以像 byte 那样节省空间。一个short变量是int型变量所占空间的二分之一;默认值是 0;例子:short s = 1000;{/callout}int{callout color="#f0ad4e"}int 数据类型是32位、有符号的以二进制补码表示的整数;最小值是 -2,147,483,648(-2^31);最大值是 2,147,483,647(2^31 - 1);一般地整型变量默认为 int 类型;默认值是 0 例子:int a = 100000;{/callout}long{callout color="#f0ad4e"}long 数据类型是 64 位、有符号的以二进制补码表示的整数;最小值是 -9,223,372,036,854,775,808(-2^63);最大值是 9,223,372,036,854,775,807(2^63 -1);这种类型主要使用在需要比较大整数的系统上;默认值是 0L;例子: long a = 100000L;"L"理论上不分大小写,但是若写成"l"容易与数字"1"混淆,不容易分辩。所以最好大写。{/callout}float{callout color="#f0ad4e"}float 数据类型是单精度、32位、符合IEEE 754标准的浮点数;float 在储存大型浮点数组的时候可节省内存空间;默认值是 0.0f;浮点数不能用来表示精确的值,如货币;例子:float f = 234.5f;{/callout}double{callout color="#f0ad4e"}double 数据类型是双精度、64 位、符合 IEEE 754 标准的浮点数;浮点数的默认类型为 double 类型;double类型同样不能表示精确的值,如货币;默认值是 0.0d;例子:double d = 7.5 ;{/callout}boolean{callout color="#f0ad4e"}boolean数据类型表示一位的信息;只有两个取值:true 和 false;这种类型只作为一种标志来记录 true/false 情况;默认值是 false;例子:boolean one = true;{/callout}char{callout color="#f0ad4e"}char 类型是一个单一的 16 位 Unicode 字符;最小值是 \u0000(十进制等效值为 0);最大值是 \uffff(即为 65535);char 数据类型可以储存任何字符;例子:char sex = '男';{/callout}代码练习public class HelloWord { public static void main(String[] args) { String name = "通讯员"; int age = 18; char sex = '男'; double height = 176.5; byte a = 1; short b = 200; long l = 3000L; float f = 123.34F; boolean bl = true; } }
2023年07月13日
150 阅读
0 评论
0 点赞