repot選択画面へ戻る

Report#4{〜12/25(Mon)}

  • オフライン試験のQ23〜Q38のついて考察せよ。
  • 目次

    1. 課題

    2. 問23〜問33
    3. 問34
    4.     
    5. 問35〜36
    6.                
    7. 問37
    8.           
    9. 問38
    10.      

    課題

    オフライン試験のQ23〜Q38のついて考察せよ。

  • コードと実行結果を示し、各問について考察すること。
  • 問23〜33


    01;  class report6_23_33 {
    02;	 public static void main(String arg[]) {
    03;	
    04;  //問23------------------------------------------
    05;  	System.out.println("---Q23---");
    06;  	
    07;  	int x1,y;
    08;  	x1 = 100; x1 += 1; x1--; y = 200 + x1;
    09; 	System.out.println(y++);
    10; 	
    11;  //問24------------------------------------------
    12;          System.out.println("---Q24---");
    13;  
    14;          int a1 = 0, x2 = 0;
    15;          a1 = 5; a1 += 3; x2 = ++a1;
    16;          System.out.println(x2);
    17;  
    18;  
    19;  //問25------------------------------------------
    20;          System.out.println("---Q25---");
    21;  
    22;          int a2 = 9, b1 = 3;
    23;          a2 /= b1;
    24;          System.out.println(a2 %= b1);
    25;  
    26;  
    27;  //問26------------------------------------------
    28;          System.out.println("---Q26---");
    29;  
    30;          int i1, j1;
    31;          for(i1=0, j1=0; i1<3; i1++) ++j1;
    32;          System.out.println(i1 * j1);
    33; 
    34;  
    35;  //問27------------------------------------------
    36;          System.out.println("---Q27---");
    37;  
    38;          int i2 = 2;
    39;          while(i2-- > 0) System.out.print(i2);
    40;  
    41;  
    42;  //問28------------------------------------------
    43;          System.out.println("¥n---Q28---");
    44;  
    45;          int num1 = 10000;
    46;          for(int i3 = 0; i3 < 4; i3++) num1 >>= i3;
    47;          System.out.println(num1);
    48;  
    49;  
    50;  //問29------------------------------------------
    51;          System.out.println("---Q29---");
    52;  
    53;          int num2 = 0;
    54;          for(int i4 =1; i4 <= 10; i4++){
    55;            if(++num2 % i4 == 0) num2++;
    56;          }
    57;          System.out.println(++num2);
    58;  
    60;  
    61;  //問30------------------------------------------
    62;          System.out.println("---Q30---");
    63;  
    64;          int a3 = 9;
    65;          if(a3++ != 10 | a3++ == 10) a3++;
    66;          System.out.println(a3);
    67;  
    68;  
    69;  //問31------------------------------------------
    70;          System.out.println("---Q31---");
    71;  
    72;          for(int i5 = 0; i5 < 5; i5++)
    73;              System.out.println("i == " + i5);
    74;          System.out.println("Hello");
    75;  
    76;  
    77;  //問32------------------------------------------
    78;          System.out.println("---Q32---");
    79;  
    80;          int i6;
    81;          for(i6 = 0; i6 < 9; i6 += 3) {}
    82;          System.out.println(i6);
    83;  
    84;  
    85;  //問33------------------------------------------
    86;          System.out.println("---Q33---");
    87;  
    88;          for(int i7 = 0; i7 < 8; i7++) {
    89;              System.out.println(i7);
    90;              i7 += 3;
    91;          }
    92;      }
    93;  }
       

  • 実行結果


  • ---Q23---
    300
    ---Q24---
    9
    ---Q25---
    0
    ---Q26---
    9
    ---Q27---
    10
    ---Q28---
    156
    ---Q29---
    12
    ---Q30---
    12
    ---Q31---
    i == 0
    i == 1
    i == 2
    i == 3
    i == 4
    Hello
    ---Q32---
    9
    ---Q33---
    0
    4
    

    問22〜33の考察

     
  • 問23
  •   
  • 問24
  •   
  • 問25
  •   
  • 問26
  •   
  • 問27
  •   
  • 問28
  •   
  • 問29
  •   
  • 問30
  •   
  • 問31
  •   
  • 問32
  •   
  • 問33
  •   

    問34

  • ソース


  • 01;  class report6_34 {
    02;      public static void main(String args[]) {
    03;        int i = 0;
    04;          for(sayHello(); i <= 6; i += 3) {
    05;              sayHello();
    06;          }
    07;      }
    08;      static void sayHello() {
    09;          System.out.println("Hello");
    10;      }
    11;  }
    

  • 実行結果


  • Hello
    Hello
    Hello
    Hello
    

    問34の考察

    問35〜36

  • ソース


  • 01;  class report6_35_36{
    02;      public static void main(String args[]) {
    03;          Player p1 = new Player();
    04;          Player p2 = new Player();
    05;          p1.id = 1000;
    06;          p2.id = 2000;
    07;  //問35-------------------------------------------
    08;          System.out.println("------Q35------");
    09;
    10;          p1.num += p1.id;
    11;          p1.num += p2.id;
    12;          System.out.println(Player.num);
    13;
    14;
    15;  //問36-------------------------------------------
    16;          System.out.println("------Q36------");
    17;  
    18;          Player.num2 += p1.id;
    19;          Player.num2 += p2.id;
    20;          System.out.println("p1.num == " + p1.num2);
    21;          System.out.println("p2.num == " + p2.num2);
    22;
    23;      }
    24;  }
    25;  class Player {
    26;      int id = 0;
    27;      static int num = 0, num2 =0;
    28;  }
    

  • 実行結果


  • ------Q35------
    3000
    ------Q36------
    p1.num == 3000
    p2.num == 3000
    

    問35〜36の考察

    問37

  • ソース

  • 01;  class report6_37 {
    02;      public static void main(String args[]) {
    03;           Card c1 = new Card();
    04;          Card c2 = new Card();
    05;          Card c3 = c1;
    06;          c1.deposit = 1000;
    07;          c2.deposit = 2000;
    08;          c3.deposit = 3000;
    09;          int sum = c1.deposit + c2.deposit + c3.deposit;
    10;          System.out.println(sum);
    11;      }
    12;   }
    13;  class Card {
    14;       int deposit;
    15;  }
    

  • 実行結果

  • 8000
    

    問37の考察

    問38

  • ソース

  • 01;  class Test4 {
    02;      public static void main(String args[]) {
    03;          Card c1 = new Card();
    04;          Card c2 = c1;
    05;          c1.deposit = 1000;
    06;          c2.deposit = 2000;
    07;          Bank.useCard(c1);
    08;          Bank.useCard(c2);
    09;          /* A */
    10;  //追加---------------------
    11;  
    12;    System.out.println("c1.deposit == " + c1.deposit);
    13;    System.out.println("c2.deposit == " + c2.deposit);
    14; 
    15;  //-------------------------
    16;      }
    17;  }
    18;  class Card { int deposit; }
    19;  	class Bank {
    20;      public static void useCard( Card c ) {
    21;          c.deposit -= 500;
    22;      }
    23;  }
    

  • 実行結果

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

    問38の考察

    感想

    参考文献

    repot選択画面へ戻る

    topへ戻る