美文网首页
JAVA 1 2 课

JAVA 1 2 课

作者: 一二三四五丶 | 来源:发表于2015-12-23 17:26 被阅读23次

(1)byte(字节型) 1字节
short(短整型) 2字节
int(整型) 4字节
long(长整型)8字节
float(单精度)4字节
double (双精度)8字节
char (字符型) 1字节
bolean (布尔型) 1 or 4字节

(2)% 取余数

public class ASD{ public static void main(String[] args) { int i =5; int o =2; System.out.println(i%o);} }

3)string 类 首字母大写

4)一对小括号代表一个方法

5)length 字符串长度

String str = "asdfads"; int charLen = str.length(); System.out.println(charLen);

6)compareTo 比较 结果int型

7)等号 == 双等号 if 如果if只有一条语句{ } 可以去掉

public class ASD{ public static void main(String[] args) { String str1 = "Google"; String str2 = "google"; int result = str1.compareTo(str2); if (result == 0) { System.out.println("111"); }else { System.out.println("22222"); } System.out.println(result);} }

8)compareToIgnoreCase 忽略大小写

public class ASD{ public static void main(String[] args) { String str1 = "foogle"; String str2 = "google"; int result = str1.compareTo(str2); System.out.println(result); } }

9)equals 等于 结果只有 等于 不等于

public class ASD{ public static void main(String[] args) { String str1 = "Google"; String str2 = "google"; if (str1.equals(str2)); System.out.println("str1=str2"); } }

10)indexOf 寻找后面的字符在字符串第一次出现的位置 没找到返回-1

      空格也算一个位置 (" ",5)  从第5个位置开始找

public class ASD{ public static void main(String[] args) { String str1 = "Google djfsao"; int index1=str1.indexOf("o",5); System.out.println(index1);} }

11)startsWith 前缀

public class ASD{ public static void main(String[] args) { String str1 = "Google djfsao"; boolean isStare = str1.startsWith("G"); System.out.println(isStare);} }

12)endsWith 后缀

public class ASD{ public static void main(String[] args) { String str1 = "Google djfsao"; boolean endWith = str1.endsWith("G"); System.out.println(endWith);}}

相关文章

网友评论

      本文标题:JAVA 1 2 课

      本文链接:https://www.haomeiwen.com/subject/dkjvhttx.html