随手记JAVA开发面试_Java随手记

(一)JAVA的初级入门随手记 —12月22日

入门程序,输出一个Hello_World;

CMD+B运行

// class是创建的一个类,保存的文件名字一定要和Class后的名字一样,大小写都要一致

public class Zhang {

// main主要的,程序的入口

public static void main(String[] args) {

// system语句是输出语句,每条语句后以分号结尾

// println 是表示输出换行

System.out.println("Hello_World");

}

}

(二)JAVA的基本数据类型以及转换 —12月23日

基本数据类型 运算符:+ 加法,— 减法,* 乘法,/ 除法,%是取余

整形:byte(占用1个字节),short(占用2个字节),int(占用4个字节),long(占用8个字节)

浮点型:float(占用4个字节),double(占用8个字节)

字符型:char(占用1个字节)

BOOL型:True,False(占用1或4个字节)

final常量

类型转换

public class JavaText {

public static void main(String[] args) {

// 隐式转换:空间占用小的类型转换为空间占用大的类型,精度不丢失。如

short s =97;

int i= sh;

System.out.println("隐式转换"+i);

// 强制转换

long l=1111;

int jj=(int)ll;

System.out.println("强制转换"+jj);

}

}

字符串的使用

String 是字符串的一种类

( )是一种方法,方法的后面都会写上( )

public class JavaText {

public static void main(String[] args) {

// 创建字符串

String str1 = "JAVA练习测试";

// 字符串长度的方法,返回的是int型

int le = str1.length();

System.out.println("字符串的长度为:"+le);

String str2 = "Java练习测试";

// 字符串比较的方法,返回的是int型

int result = str1.compareTo(str2);

System.out.println("字符串1比字符串2大 "+result+" 位");

// 用if语句进行判断

if (str1.compareTo(str2) == 0) {

System.out.println("字符串1等于字符串2");

}

if (str1.compareTo(str2) > 0) {

System.out.println("字符串1大于字符串2");

}

if (str1.compareTo(str2) < 0) {

System.out.println("字符串1小于字符串2");

}

// 字符串不分大小写的比较

if (str1.compareToIgnoreCase(str2) == 0) {

System.out.println("字符串1等于字符串2");

}

if (str1.compareToIgnoreCase(str2) > 0) {

System.out.println("字符串1大于字符串2");

}

if (str1.compareToIgnoreCase(str2) < 0) {

System.out.println("字符串1小于字符串2");

}

// 字符串比较,返回BOOL型

if (str1.equals(str2)) {

System.out.println("str1 等于 str2");

}else{

System.out.println("str1 不等于 str2");

}

// 查找字符串中的字符,返回int型

int index1 = str1.indexOf("J");

System.out.println("J字符在字符串总第" + index1 +"位");

// 从第X位开始查找字符串中的字符,如果该字符串中没有要查找的字符则返回的是-1

int index2 = str1.indexOf("S",4);

System.out.println("S字符在字符串总第" + index2 +"位");

// 前缀,

boolean bool1= str1.startsWith("J");

System.out.println("该字符串是否是以J字符开头:" + bool1);

boolean bool2 = str2.startsWith("S");

System.out.println("该字符串是否是以S字符结尾:" + bool2);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值