Skip to content

Activity 2: Types and Logic

Instructions

Example Code

Question 6

 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
public class Assign1 {
    public static void main(String[] args) { 

        int int_ = 3;
        long long_ = 3L;
        float float_ = 3.0F;
        double double_ = 3.0;

        int_ = int_;
        int_ = long_;      // illegal
        int_ = float_;     // illegal
        int_ = double_;    // illegal

        long_ = int_;
        long_ = long_;
        long_ = float_;    // illegal
        long_ = double_;   // illegal

        float_ = int_;
        float_ = long_;
        float_ = float_;
        float_ = double_;  // illegal

        double_ = int_;
        double_ = long_;
        double_ = float_;
        double_ = double_;

        int_ = '0';
        int_ = false;      // illegal
        double_ = '0';
        double_ = false;   // illegal

    }
}

Question 7

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Assign2 {
    public static void main(String[] args) { 

        byte miles;
        short minutes;
        int checking;
        long days;
        float total;
        double sum;
        boolean flag;
        char letter;

        checking = 56000;
        total = 0;
        sum = total;
        total = sum;
        checking = miles;
        sum = checking;
        flag = minutes;
        days = '0';

    }
}