Java
instanceof判断是否是该类型
public static void main (String[] args) {
double d=10.0;
System.out.println((Object)d instanceof Double);
}
结果为:true
注:这里需要对类型做一个转换 (Object,Double属于封装类)
main方法
一般的main方法
public static void main(String[] args){
System.out.println("此处打印");
}
无main方法,需要注意多个@Test时,这使用最后一个方法
@Test
public void 方法1(){
System.out.println("此处不打印");
}
@Test
public void 方法2(){
System.out.println("此处打印");
}
字符型输入输出
Scanner sc=new Scanner(System.in);
String s=sc.next();
char a=s.charAt(0);
此处的0表示获取第0个字符(同数组下标)
整型输入输出
Scanner sc=new Scanner(Sysem.in);
int s=sc.nextInt();//吸收下一行
sc.nextLine();//做一个缓冲
自动排序数组
Arrays.sort(数组名);
随机生成数字
int 类型名=new Random().nextInt(100);//0-100的范围
字符串是否相等比较
equse("字符串");返回的是boolean类型(区分大小写)
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str = sc.next();
if(str.equals("a")){
System.out.println("相等");
}else{
System.out.println("不相等");
}
}
equalsIgnoreCase("字符串");忽略大小写
增强for循环
for(类型 类型名:数组名){
System.out.println(类型名);
}
相当于
for(int i=0;i<数组名.length;i++){
System.out.println(数组名[i]);
}
Math函数
Math.sqrt()
: 计算平方根
Math.cbrt()
: 计算立方根
Math.pow(a, b)
: 计算a的b次方
Math.max( , )
: 计算最大值
Math.min( , )
: 计算最小值
Math.abs()
: 取绝对值
Math.round()
: 四舍五入(向上取整),float时返回int类型的值,double时返回long类型的值
Math.random()
: 取得一个[0, 1)范围内的随机数
package com.cdz;
/*
* 有参有返回值
* 运用math函数
*/
public class math {
public static void main(String[] args) {
int a =10;
int b=20;
System.out.println(fangFa1(a,b));
}
public static int fangFa1(int a,int b) {
return Math.max(a, b);//比较较大的哪个值
//return Math.min(a, b);//比较较小的哪个值
}
}
Html
跑马灯<marguee> </marguee>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<marquee scrollamount="10" direction="right" behavior="scroll">你是猪吗?</marquee>
</body>
</html>
参数:scrollamount 设置1秒多少像素移动
direction 设置方向(共4种)
behavior 设置行为(默认3种:alternate(目的地反向移动),slide(目的地停止),scroll(循环))
事件确定删除
if(confirm("确定删除吗")){
return true;
}
return false;
页面刷新
location.reload(true);
jQuery实现上传图片时,显示图片预览效果
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery上传图片时,可以显示图片预览效果</title>
<script src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<input id="myfile" type="file"><br/>
<img src="" id="show" width="200">
<script type="text/javascript">
$(function() {
$("#myfile").change(function() {
var readFile = new FileReader();
var mfile = $("#myfile")[0].files[0]; //注意这里必须时$("#myfile")[0],document.getElementById('file')等价与$("#myfile")[0]
readFile.readAsDataURL(mfile);
readFile.onload = function() {
var img = $("#show");
img.attr("src", this.result);
}
});
})
</script>
</body>
</html>