Report#4

課題


目次

1.試験問題Q23    2.試験問題Q24   3.試験問題Q25   4.試験問題Q26 
5.試験問題Q27    6.試験問題Q28   7.試験問題Q29   8.試験問題Q30 
9.試験問題Q31     10.試験問題Q32   11.試験問題Q33   12.試験問題Q34 
13.試験問題Q35   14.試験問題Q36   15.試験問題Q37   16.試験問題Q38
17.感想・反省

1.試験問題Q23

ソースコード

public class Test {
    public static void main(String[] args) {
        int x,y;
        x = 100;  x += 1;  x--;  y = 200 + x;
        System.out.println(y++);
    }
}

実行結果

300

考察

2.試験問題Q24

ソースコード

public class Test {
    public static void main(String[] args) {
        int a=0, x=0;
        a = 5; a += 3; x = ++a;
        System.out.println(x);
    }
}

実行結果

9

考察

3.試験問題Q25

public class Test {
    public static void main(String[] args) {
            int a=9, b=3;
            a /= b;
            System.out.println(a %= b);
        }
}
実行結果
0

考察

4.試験問題Q26

ソースコード

public class Test {
        public static void main(String[] args) {
        int i, j;
        for(i=0, j=0; i<3; i++) ++j;
        System.out.println(i * j);
        }
}

実行結果

9

考察

5.試験問題Q27

ソースコード

public class Test {
        public static void main(String[] args) {
                int i=2;
                while(i-- > 0) System.out.print(i);
        }
}

実行結果

10

考察

6.試験問題Q28ソース

ソースコード

public class Test {
        public static void main(String[] args) {
                int num=10000;
                for(int i = 0; i < 4; i++) num >>= i;
                System.out.println(num);
        }
}

実行結果

156

考察

7.試験問題Q29

ソースコード

public class Test {
        public static void main(String[] args) {
                int num = 0;
                for(int i = 1; i <= 10; i++) {
                        if (++num % i == 0) num++;
                }
                System.out.println(++num);
        }
}

実行結果

12

考察

8.試験問題Q30

ソースコード

public class Test {
        public static void main(String[] args) {
                int a = 9;
                if(a++ != 10 | a++ == 10) a++;
                System.out.println(a);
        }
}

実行結果

12

考察

9.試験問題Q31

ソースコード

public class Test {
        public static void main(String[] args) {
                for(int i = 0; i<5; i++)
                System.out.println("i == " + i);
                System.out.println("Hello");
        }
}

実行結果

i == 0
i == 1
i == 2
i == 3
i == 4
Hello

考察

10.試験問題Q32

ソースコード

public class Test {
        public static void main(String[] args) {
                int i;
                for(i = 0; i<9; i+=3) {}
                System.out.println(i);
        }
}

実行結果

9

考察

11.試験問題Q33

ソースコード

public class Test {
        public static void main(String[] args) {
                for(int i = 0; i<8; i++) {
                  System.out.println(i);
                  i += 3;
                }
        }
}

実行結果

0
4

考察

12.試験問題Q34

ソースコード

public class Test {
        public static void main(String[] args) {
          int i = 0;
          for(sayHello(); i <= 6; i += 3) {
            sayHello();
          }
        }
        static void sayHello() {
          System.out.println("Hello");
        }
}

実行結果

Hello
Hello
Hello
Hello

考察

13.試験問題Q35

ソースコード

public class Test {
         public static void main(String[] args) {
           Player p1 = new Player();
           Player p2 = new Player();
           p1.id = 1000;
           p2.id = 2000;
           p1.num += p1.id;
           p2.num += p2.id;
           System.out.println(Player.num);
        }
}
class Player {
  int id = 0;
  static int num = 0;
}

実行結果

3000

考察

14.試験問題Q36

ソースコード

public class Test {
         public static void main(String[] args) {
           Player p1 = new Player();
           Player p2 = new Player();
           p1.id = 1000;
           p2.id = 2000;
           Player.num += p1.id;
           Player.num += p2.id;
           System.out.println("p1.num == " + p1.num);
           System.out.println("p2.num == " + p2.num);
        }
}
class Player {
  int id = 0;
  static int num = 0;
}

実行結果

p1.num == 3000
p2.num == 3000

考察

15.試験問題Q37

public class Test {
         public static void main(String[] args) {
           Card c1 = new Card();
           Card c2 = new Card();
           Card c3 = c1;
           c1.deposit = 1000;
           c2.deposit = 2000;
           c3.deposit = 3000;
           int sum = c1.deposit + c2.deposit + c3.deposit;
           System.out.println(sum);
        }
}
class Card {
  int deposit;
}

実行結果

8000

考察

16.試験問題Q38

ソースコード

public class Test {
         public static void main(String[] args) {
           Card c1 = new Card();
           Card c2 = c1;
           c1.deposit = 1000;
           c2.deposit = 2000;
           Bank.useCard(c1);
           Bank.useCard(c2);
           /* A */
           System.out.println("c1.deposit == " + c1.deposit);
           System.out.println("c2.deposit == " + c2.deposit);
        }
}
class Card { int deposit; }
class Bank {
   public static void useCard(Card c) {
     c.deposit -= 500;
   }
}

実行結果

c1.deposit == 1000
c2.deposit == 1000

考察

感想・反省

今回は筆記のテストが非常に悪かったです。c言語がわかればできるんじゃない かとなめていました。期末はしっかりしたい。