Java入门(小记)

 【...】

对我其实...还在敲门   

【代码】

package hello;
 
import java.util.Scanner;   
   
public class Hello{  
	
    public static void main(String[] args){ 
    	System.out.println("你好");
        Scanner in = new Scanner(System.in);  
        int amount,price;
        System.out.print("请输入票面");
        amount = in.nextInt();
        System.out.print("请输入金额");
        price = in.nextInt();
        System.out.println(amount+"-"+price+"="+(amount-price));
    }
} 

【测试】

【随机数】

package hello;
 
import java.util.Scanner;   
   
public class Hello{  
	
    public static void main(String[] args){ 
       
        Scanner in = new Scanner(System.in);  
        int number=(int)(Math.random()*100+1); //[0,1)-->[0,100)-->[1,100]
        int a,count=0;
        do
        {
        	a=in.nextInt();
        	count++;
        	if(a>number)
        		System.out.println("偏大");
        	else
        		System.out.println("偏小");
        }while(a!=number);
        System.out.println("恭喜你猜对了,你猜了"+count+"次");
    } 
}

【...】

1. 快捷方式(部分)
Alt+/   内容辅助
Ctr+/  在当前行加注释
Shift+Left/Right  选中上一个/下一个字符
Shift+Up/Down  选中上一行/下一行(从当前光标位置开始)
Ctrl+F  查找并替换 
Ctrl+Z  撤销 
Ctrl+X  剪切
Ctrl+A  全部选中
Ctrl+Shift+Enter  在当前行上插入一行
Shift+Enter  在当前行下插入一行 
Ctrl+=  全局放大
Ctrl+-  全局缩小
Ctrl+S  保存
Ctrl+Shift+S  保存所有
Ctrl+Shift+L  显示快捷键帮助

2. Scanner in = new Scanner(System.in);  

输入: 变量名=in.nextInt();(输入一个整数)

变量名=in.nextDouble();(输入一个浮点数)//浮点数运算存在误差

扫描二维码关注公众号,回复: 2830360 查看本文章

3. println  输出带回车   print  输出不带回车

4. 定义变量:数据类型 变量名;

5. 类型转换:1.自动转换        2.强制转换  (转换类型)值

6.关系运算符

7.判断浮点数是否相等  :Math.abs(f1-f2)<1e-6

保留小数位数时自动四舍五入

8.条件判断 if else

9.调试

10.逻辑类型 boolean   逻辑运算优先级:!> && > ||

【运算符优先级】

【标记】

猜你喜欢

转载自blog.csdn.net/qq_41117236/article/details/81434184