hooyantsing's Blog

第6次课程

字数统计: 959阅读时长: 5 min
2019/04/22

源辰74班

第6次课程

04.22.2019

内容

1.回顾

2.[项目]圣诞树

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package Test0422;
import java.util.Scanner;
public class shengdanshu {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("请输入行数:");
       int n = sc.nextInt();
       for (int i = 1; i <= n - 2; i++) {
           for (int j = 1; j <= n - i; j++)  {
               System.out.print(" ");
           }
           for (int k = 1; k <= i * 2 - 1;  k++) {
               if (k == 1 || k == i * 2 - 1  || i == n - 2) {
                  System.out.print("*");
               } else {
                  System.out.print(" ");
               }
           }
           System.out.println();
       }
       for (int i = 1; i <= n; i++) {
           for (int j = 1; j <= n - i; j++)  {
               System.out.print(" ");
           }
           for (int k = 1; k <= i * 2 - 1;  k++) {
               System.out.print("*");
           }
           System.out.println();
       }
       if (n % 2 == 0) {
           // 偶数行自适应树干
           for (int i = 1; i <= n; i++) {
               for (int j = 1; j <= n / 2;  j++) {
                  System.out.print(" ");
               }
               for (int k = 1; k <= n - 1;  k++) {
                  System.out.print("*");
               }
               System.out.println();
           }
       } else {
           // 奇数行自适应树干
           for (int i = 1; i <= n; i++) {
               for (int j = 1; j <= n / 2;  j++) {
                  System.out.print(" ");
               }
               for (int k = 1; k <= n; k++)  {
                  System.out.print("*");
               }
               System.out.println();
           }
       }
    }
}

3.[项目]三值最大

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package Test0422;
import java.util.Scanner;
public class bijiaodaxiao {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("请输入三个数:"); //n1 n2 n3
       int x = sc.nextInt();
       int y = sc.nextInt();
       int z = sc.nextInt();
       int max=x>y?x:y;
       max=max>z?max:z;
       System.out.println("最大值为:"+max);
       
    }
}

4.[项目]电话费

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Test0422;
import java.util.*;
public class dianhuafei {
    private static final int PACKAGE = 180;
    private static final double MONEY1 =  0.2;
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("请输入通话时长(秒):");
       int times = sc.nextInt();
       double fee = 0.0;
       if (times < 0) {
           System.out.println("错误代码001:通话时间不能为负值!");
       } else {
           if (times <= PACKAGE) {
               fee = MONEY1;
           } else {// times-MONEY1为int型,结果取整数
               fee = MONEY1 + (times -  MONEY1) / 60 * 0.1;
               if (times % 60 != 0) {
                  fee = fee + 0.1;
               }
           }
           System.out.println("通话时长为:"  + times + "秒,收费为:" + fee + "元");
       }
    }
}

5.[项目]出租车

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package Test0422;
import java.util.*;
public class chuzuche {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("请输入里程数(公里):");
       double miles = sc.nextDouble();
       System.out.println("等待时间(秒):");
       int seconds = sc.nextInt();
       int fee = 10;
       if (miles > 3) {
           fee = fee + (int) ((miles - 3) /  0.5);
       }
       fee = fee + seconds / 150;
       if (miles > 15) {
           fee = fee + (int) (fee * 0.5);
       }
       System.out.println("行驶里程:" +  miles + "公里,等待时间:" + seconds + "秒,收费:" + fee + "元");
    }
}

6.[项目]分等级

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package Test0422;
import java.util.Scanner;
public class dengji {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("请输入一个分数:");
       int score = sc.nextInt();
       if(score>=90) {
           System.out.println("A级");
       }else if(score>=80){
           System.out.println("B级");
       }else if(score>=70){
           System.out.println("C级");
       }else if(score>=60){
           System.out.println("D级");
       }else {
           System.out.println("E级");
       }
    }
}

7.[项目]奇数和

1
2
3
4
5
6
7
8
9
10
11
12
13
package Test0422;
public class jishuqiuhe {
    public static void main(String[] args) {
       int sum = 0;
       for(int i=1;i<=100;i++) {
           if(i%2==1) {
               sum = sum + i;
           }
       }
       System.out.println("总和:"+sum);
       
    }
}

8.Debug功能应用

一、调试(甲壳虫)

7f75c1b7f0847e859f5e408e1b0ebaf6.png

二、打开调试界面

0d287f0c29a49fa3ec1f63bd75346d53.png

三、功能使用

1.调试工作区清空

1e2378bd1034f18c9d7ee9b7b502be56.png

“调试”工作区内,”全部终止/断开连接”->”除去所有终止的操作”。

2.断点

断点含义:调试时,程序执行到断点处将停止。

310889032ae2d8966485146f531db144.png

双击源码工作区左侧滑动条,出现圆球则断点。

3.直接运行程序及单步运行程序

19074fabbe983710c92625de3999bfe9.png

           (停止)     (下一步)                   (直接运行到下一个断点)

4.查看变量状态

5d67ba0b2c1c596538a42139dede8e29.png

可在”变量”工作区查看。

其他

****作业附件:

作业题4_学生.doc

CATALOG