IntelliJ Idea 常用快捷键

快捷键         功能
Ctrl+Y         删除光标所在行
Ctrl+D         复制光标所在行的内容,插入光标位置下面
Ctrl+Alt+L     格式化代码
Ctrl+/         单行注释
Ctrl+Shift+/     选中代码注释,多行注释,再按取消注释
Alt+Shift+上下箭头     移动当前代码行
shift+回车        光标跳到下一行
Alt+斜杠        自动补全


Alt+insert        无参构造方法
(或者右键+Generate)

Alt+insert        增加有参构造
(或者右键+Generate)

Alt+insert        提供get/set方法
(或者右键+Generate)

psvm+回车 :main方法

sout+回车:输出语句


ctrl+shift+F10 运行

1.1编写方法ASCII码表转换为对应的字符 

/*
    定义getChar方法,能够将数字,根据ASCII码表,转换为对应的字符并返回,只转换大小写字母和数字字符。
    代码实现:
        字符:d

        编写步骤: 1. 定义getChar方法,参数为(int num),返回值char类型
        2. 在getChar方法中,将传入的参数num转成char类型变量ch
        3. 在getChar方法中判断chs是否是小写字母.如果是返回ch
        4. 在getChar方法中判断chs是否是大写字母.如果是返回ch
        5. 在getChar方法中判断chs是否是数字字符.如果是返回ch
        6. 其他情况返回' ' 
        7. 在main方法中调用getChar方法,传入一个数字.使用aChar变量接收getChar方法的返回值 8. 输出aChar变量
 */
public class Test4 {
    public static void main(String[] args) {
        char aChar=getChar(100);
        System.out.println("字符:"+aChar);

    }
    //  定义getChar方法,能够将数字,根据ASCII码表,转换为对应的字符并返回,只转换大小写字母和数字字符。
    //参数列表:int num(定义getChar方法,参数为int num,返回值char类型)
    //返回值类型:char
    public static char getChar(int num){
      //在getChar方法中,将传入的参数num转成char类型变量ch
        char ch=(char)num;
        if(ch>'a' && ch<'z'){
            return ch;
        }else if(ch>'A' && ch<'Z'){
            return ch;
        }else if(ch>'0' && ch<'9'){
            return ch;
        }else{
            return ' ';
        }
    }
}

 1.2 定义方法打印『X』对称图形

/*
    定义printX方法,打印任意的图形
    代码实现,效果如果所示:
        O********O   1   10
        *O******O*   2    9
        **O****O**   3    8
        ***O**O***   4    7
        ****OO****   5    6
        **********   5    6
        **********   4    7
        **********   3    8
        **********   2    9
        **********   1    10
 */
public class Test6 {
    public static void main(String[] args) {
        printXing(10);
    }

    //定义一个方法,打印星星
    //返回值类型:void
    //参数列表:
    public static void printXing(int m){
        for (int i = 1; i <=m ; i++) {
            for (int j = 1; j <=m ; j++) {
                if(i==j || i+j==m+1){
                    System.out.print("O");
                }else{
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
}

1.3 九九乘法表

/*
   使用方法打印九九乘法表简版
1*1=1
1*2=2	2*2=4
1*3=3	2*3=6	3*3=9
1*4=4	2*4=8	3*4=12	4*4=16
1*5=5	2*5=10	3*5=15	4*5=20	5*5=25
1*6=6	2*6=12	3*6=18	4*6=24	5*6=30	6*6=36
1*7=7	2*7=14	3*7=21	4*7=28	5*7=35	6*7=42	7*7=49
1*8=8	2*8=16	3*8=24	4*8=32	5*8=40	6*8=48	7*8=56	8*8=64
1*9=9	2*9=18	3*9=27	4*9=36	5*9=45	6*9=54	7*9=63	8*9=72	9*9=81

看到上面的结果,不知道怎么下手,先将每部分看成一颗*
*
**
***
****
*****
******
*******
********
*********


上面变成了9换行9列的三角形,三角形不会,我们会9行9列的矩形
*********
*********
*********
*********
*********
*********
*********
*********
*********
*********

 */
public class Test9 {
    public static void main(String[] args) {
        printXxx(9);
        System.out.println("---------------");
        printXxx(6);
        System.out.println("----------------");
        printXxx(12);
    }
   /*
        打印99乘法表
    */
   public static void printXxx(int count){
       for (int i = 1; i <= count; i++) {//外循环控制行i
           //通过分析发现,行数等于列数能打印出三角形,所以j<=i
           //通过分析发现,九九乘法表中 行数*列数=乘积
           for (int j = 1; j <= i; j++) {//内循环控制列
               System.out.print(i+"*"+j+"="+(i*j)+"\t");
           }
           System.out.println();
       }
   }
}

1.4 摄氏度与华氏度的相互转换

/*
    温度转换:摄氏度与华氏度的相互转换。
    代码实现,效果如图所示:
        摄氏度:30.0--华氏度为:86
        华氏度:86.0--摄氏度为:30.0

    开发提示:
        转换公式:华氏度=(9.0/5)*摄氏度+32;
 */
public class Test8 {
    public static void main(String[] args) {
        double s=30.0;
        System.out.println("摄氏度为:"+s+"°---华氏度为:"+sToh(s)+"°");

        double h=86.0;
        System.out.println("华氏度为:"+h+"°---摄氏度为:"+hTos(h)+"°");
    }
    //定义方法
    public static double sToh(double s){
        return (9.0/5)* s +32;
    }

    public static double hTos(double h){
        return (h-32)/9.0*5;
    }
}

1.5 实现四舍五入运算

/*
    定义round方法,接收一位小数,实现四舍五入运算,并返回结果。
    代码实现,效果如图所示:
        10.1->10
        10.4->10
        10.5->11
        10.9->11

        round方法中,参数+0.5后,转换成int类型,并返回。
 */
public class Test7 {
    public static void main(String[] args) {
        System.out.println(10.1+"-"+round(10.1));
        System.out.println(10.4+"-"+round(10.4));
        System.out.println(10.5+"-"+round(10.5));
        System.out.println(10.9+"-"+round(11));
    }
    //定义round方法,参数为(double d),返回值int
    public static int round(double d){
        //round 方法中,d+0.5后,转换成int类型,并返回
        int n=(int)(d+0.5);
        return n;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hyhcloud

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值