复习Java(一)基本

(根据网上Derek Banas 教学视频整理的笔记)

1. 基本word

1)

Public: All users can use this function

Static: Only one class can use this function

Void: This function does not return any values

Main: It's required in every Java program. It's always excuted first

2)

Every main function must accept an array of string objects

Class variables must start with static if you want to access them with any other methods in the class


2. Define数字类型 (例子)

1)

byte theByte = 45;

short theShort = 12345;

int theInt = 1234567890;

long theLong = 9223372036854775807L;  //记得后面有个“L"

float theFloat = 3.14F;  //记得后面有个”F"

double theDouble = 3.1234567890;

boolean theTrue = true;

2)

用Java本身的指令显示最大、最小值

System.out.println(Float.MAX_VALUE);

System.out.println(Double.MAX_VALUE);

System.out.println(Byte.MIN_VALUE);


3. Define char (例子)

char randomChar =65; 

char anotherChar='A';

  //Character Code for A is 65 Minimum value 0 Maximum value 65535

char backSpace='\b';

char formFeed='\f';

char lineFeed='\n';

char carriageReturn='\r';

char horizontalTab='\t';

char doubleQuote='\"';

char singleQuote='\'';

char backSlash='\\';

System.out.println(randomChar);

System.out.println(backSpace);

System.out.println(formFeed);

System.out.println(lineFeed);

System.out.println(carriageReturn);

System.out.println(horizontalTab);

System.out.println(doubleQuote);

System.out.println(singleQuote);

System.out.println(backSlash);

// chars can also contain escaped characters


4. Define String (例子)

String randomStrings = "random";

String anotherString="string";

String lastString= randomString +" "+anotherString;

System.out.println(lastString);

// How to convert other type to string

String byteString=Byte.toString(bigByte);

String shortString=Short.toString(bigShort);

String intString=Integer.toString(bigInt);

String longString=Long.toString(bigLong);

String floatString=Float.toString(bigFloat);

String doubleString=Double.toString(bigDouble);

String booleanString=Boolean.toString(trueOrFalse);

String charString=Character.toString(randomChar);

System.out.println(charString);

System.out.println(doubleString);


5. 转换

前面加括号,里面是要转换的类型

double doubleValue= 3.1234;

int doubleToInt=(int)doubleValue;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值