文件名称:
Java Programming Cheatsheet.pdf
开发工具:
文件大小: 8mb
下载次数: 0
上传时间: 2019-07-21
详细说明:Java Programming Cheatsheet(java 语法速查), 文档很薄只有15页,提供java基本语法的速查,而且含义各个知识点的简单代码示例,比如数组,类等等2019/717
Java Programming cheatsheet
Booleans
values
true or false
literals
true false
operations and
operators && II
a & b
//b
true
false falsefalse false
false
true
false
true
false
true
true
false
a ise
true
true
true
true
true
Comparison。 perators.
true
false
2=2
2=3
3!=2
2!=2
less than
2<13
2<2
less than or equal 2<=23<=2
greater than
13>2
2>13
greater than ar
3>=22>=3
non-negative discriminant?
(bb-4.0·a·c)>=0.0
beginning of a century?
year%100)=0
legal month?
(month >=1)&&(month <= 12)
void System. out. print(string s)
prints
void System. out. printIn(String s) print s, followed by a newline
void System. out. printIng
print a newline
arsing command-line arguments
int Integer parseInt(string s)
convert s to an int value
double Double. parseDouble(String s) convert s to a double value
long Long. parselong (String s)
convert s to a long value
Math librar
public class Math
double abs double a)
absolute value of a
double max (double a, double b)
marimum of a and b
double min(double a, double b
minimum of a and b
double sin (double theta)
sine of theta
double cos (double theta)
cosine of theta
double tan(double theta)
tangent of theta
double toRadians (double degrees) convert angle from degrees to radians
double toDegrees (double radians) convert angle from radians to degrees
double exp(double a)
exponential (ea)
double log (double a)
natural log(Loge a, nr In a)
double pow(double a, double b)
raise a to the bth power(ab)
long round (double a)
round a to the nearest integer
double random
random number in[0, 1)
double sqrt(double a)
square root of a
double E
walue of e(constant)
double Pi
value of T (constant)
The full java. lang Math APL.
https:/introcs.cs.princetoneduljava/11cheatsheet/
3115
2019/717
Java Programming cheatsheet
method call
iry return type
Integer parseInt( 123")
Integer
Int
23
Double. parseDouble( 1.5")
Double double
1.5
Nath,sqrt(5.0*5.0-4.0*4.0)
double
3.0
Math. log(Math. E)
e
Math. random
Math double random in [0, 1)
Math. round (3. 14159)
Math
lon
Math. max(1.0, 9.0)
ouble
Type conversion.
expression
expression expression
type
value
(1+2+3+4)/4.0
double
Math, sqrt(4)
double
2.0
1234"+99
String123499
11*0,25
double
2.75
〔int)11*0,25
double
2.75
11*(int)0.25
int
0
〔int)(11*0.25)
Tnt
int)2.71828
ant
Math. round (2.71828)
long
3
Cint Math. round(2. 71828)
ant
3
Integer parseInt( 1234")
1234
Anatomy of an if statement.
expression
if(ⅸx>y
seauence
int t x;
X
statements
-else statements
absolute value if (x< 0)x=x
if (x>y)
put the smaller(
value in x
int t= x
and the larger
value in y
y ti
maximum of if (x>y)max-x;
x and
eI se
error check
for
if (den == 0) System. out. printIn( Division by zero")
VISLOn
e i se
System. out. printIng Quotient = num/den)
operation
double discriminant b*b-4.0*c:
if (discriminant 0.0)
error check
System, out. println(" No real roots")
r quadratic上
eIse
System, out. printIn((b+ Math. sart(discriminant))/2.0);
System, out. printIn(c-b-Math sqrt(discriminant))/2.0);
Nested if-else statement
if
Income
0)rate=0.00
else if (income 8925)rate=0.10
else if (income< 36250 rate=0.15
else if (income 87850) rate=0. 23
else if (income 183250) rate=0.28;
else if (income 398350) rate=0.33;
else if income 400000 rate=0.35
e i se
rate=0.396
Anatomy of a while loop
https:/introcs.cs.princetoneduljava/11cheatsheet/
4/15
2019/717
Java Programming cheatsheet
Initialization is a
separate statement
continuation
while (power <=n/2)
braces ard
body
is a single
Anatomy of a for loop.
initialize another a loop contro/nom l
loop
parate
continuation
tatement
Con
Increment
for cint i=0; i.
System. out. printIngs
power)
body
compute the largest
int power=1
power of 2
while (power < n/2)
less than or equal to n
2*power
System. out. printIn(power);
compute afinite sum int sum=0
(1+2+…,+n)
for (int i =1:i<=n; i++)
sum + 1,
System. out. printIn(sum);
int product 1
ompute a finite prodi
for (in
n;i++)
n!=1×2
x n)
product *=1
System. out. printIn(product)
print a table of
for (int i=0; i < n:; i++)
function values
System. out. printIn (i ++2*Math. PI*i/n)
tring rule
ompute the ruler function for (int i=2:i <=n; i++)
(see PROGRAM 1.2.1)
ruler- ruler ++i++ruler
System. out. printIn(ruler)
Break statement.
int factor:
for (factor=2; factor <= n/factor; factor++)
if (n factor = 0) break
if (factor >n/factor)
System. out. printIn(n +"is prime")
D。 while loop
I / Scale x and y to be random in (-1, 1)
x=2.0*Math. randomO-10
y =2.0*Math. randomO-10
I while CMath sqrt(x*x+ y*y)>1.0):
(030)
Switch statement
https:/introcs.cs.princetoneduljava/11cheatsheet/
5/15
2019/717
Java Programming cheatsheet
switch (day)t
case 0: System. out. printIn( Sun"); break;
case 1: System. out. printIn( Mon"); break
case 2: System. out. printin( Tuc"): break
case 3: System.out. printIn( Wed"); break
case 4: System. out. printIng Thu"); break
case 5: System. out. printIn( fri"); break
case 6: System. out. println "Sat") break;
Array
a[o]
[1]
a[2]
a[3]
a[4]
a[5]
a[6]
a[7]
String[] SUITs =t"Clubs",Di amonds",Hearts",Spades"3:
String [] RANKs=t
2","3","4","5","6","7","8","9","10
Jack", Queen",King",A
create an array
double[] a= new double [n]
for (int
with randot
0;imax) max =a[i]
double sum=0.0:
compute the average of for (int i=0;i n; i++)
the array values
sum + a[i]
double average= sum /n;
for (int i =0; i< n/2; i++)
reverse the valu
double temp= ali]:
within an array
a[i]=a[n-1-订];
a[n-i-1]= tem
copy sequence of value
double[] b= new double [n]
to another arra
for (int i =0;i
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.