オフライン試験のQ23〜Q38のついて考察せよ。{〜12/25(Mon)} コードと実行結果を示し、各問について考察すること。
ソースコード
1 class test23{ 2 public static void main(String argv[]){ 3 int x,y; 4 x = 100; 5 x += 1; 6 x--; 7 y = 200 + x; 8 System.out.println(y++); 9 } 10 } |
実行結果
1 [isatakuma-no-ibook-g4:~] j06003% java test23 2 300 |
ソースコード
1 class test24{ 2 public static void main(String argv[]){ 3 int a=0, x=0; 4 a = 5; 5 a += 3; 6 x = ++a; 7 System.out.println(x); 8 } 9 } |
実行結果
1 [isatakuma-no-ibook-g4:~] j06003% java test24 2 9 |
ソースコード
1 class test25{ 2 public static void main(String argv[]){ 3 int a=9, b=3; 4 a /= b; 5 System.out.println(a %= b); 6 } 7 } |
実行結果
1 [isatakuma-no-ibook-g4:~] j06003% java test25 2 0 |
ソースコード
1 class test26{ 2 public static void main(String argv[]){ 3 int i, j; 4 for(i=0,j=0; i<3; i++) ++j; 5 System.out.println(i * j); 6 } 7 } |
実行結果
1 [isatakuma-no-ibook-g4:~] j06003% java test26 2 9 |
ソースコード
1 class test27{ 2 public static void main(String argv[]){ 3 int i=2; 4 while(i-- > 0) 5 System.out.println(i); 6 } 7 } |
実行結果
1 [isatakuma-no-ibook-g4:~] j06003% java test27 2 1 3 0 |
ソースコード
1 class test28{ 2 public static void main(String argv[]){ 3 int num=10000; 4 for(int i = 0; i < 4; i++) num >>=i; 5 System.out.println(num); 6 } 7 } |
実行結果
1 [isatakuma-no-ibook-g4:~] j06003% java test28 2 156 |
ソースコード
1 class test29{ 2 public static void main(String argv[]){ 3 int num = 0; 4 for(int i = 1; i <= 10; i++){ 5 if(++num % i ==0) num++; 6 } 7 System.out.println(++num); 8 } 9 } |
実行結果
1 [nw0603:~] j06003% java test29 2 12 |
ソースコード
1 class test30{ 2 public static void main(String argv[]){ 3 int a = 9; 4 if(a++ != 10 | a++ ==10) a++; 5 System.out.println(a); 6 } 7 } |
実行結果
1 [nw0603:~] j06003% java test30 2 12 |
ソースコード
1 class test31{ 2 public static void main(String argv[]){ 3 for(int i=0; i < 5; i++) 4 System.out.println("i == " + i); 5 System.out.println("Hello"); 6 } 7 } |
実行結果
1 [nw0603:~] j06003% java test31 2 i == 0 3 i == 1 4 i == 2 5 i == 3 6 i == 4 7 Hello |
ソースコード
1 class test32{ 2 public static void main(String argv[]){ 3 int i; 4 for(i = 0; i < 9; i += 3){} 5 System.out.println(i); 6 } 7 } |
実行結果
1 [nw0603:~] j06003% java test32 2 9 |
ソースコード
1 class test33{ 2 public static void main(String argv[]){ 3 for(int i=0; i < 8; i++){ 4 System.out.println(i); 5 i += 3; 6 } 7 } 8 } |
実行結果
1 [nw0603:~] j06003% java test33 2 0 3 4 |
ソースコード
1 class test34{ 2 public static void main(String argv[]){ 3 int i = 0; 4 for(sayHello(); i <= 6; i += 3){ 5 sayHello(); 6 } 7 } 8 9 static void sayHello(){ 10 System.out.println("Hello"); 11 } 12 } |
実行結果
1 [nw0603:~] j06003% java test34 2 Hello 3 Hello 4 Hello 5 Hello |
ソースコード
1 class test35{ 2 public static void main(String argv[]){ 3 Player p1 = new Player(); 4 Player p2 = new Player(); 5 p1.id = 1000; 6 p2.id = 2000; 7 p1.num += p1.id; 8 p2.num += p2.id; 9 System.out.println(Player.num); 10 } 11 } 12 13 class Player{ 14 int id =0; 15 static int num = 0; 16 } |
実行結果
1 [nw0603:~] j06003% java test35 2 3000 |
ソースコード
1 class test36{ 2 public static void main(String argv[]){ 3 Player1 p1 = new Player1(); 4 Player1 p2 = new Player1(); 5 p1.id = 1000; 6 p2.id = 2000; 7 Player1.num += p1.id; 8 Player1.num += p2.id; 9 System.out.println("p1.num =="+p1.num); 10 System.out.println("p2.num =="+p2.num); 11 } 12 } 13 14 class Player1{ 15 int id = 0; 16 static int num = 0; 17 } |
実行結果
1 [nw0603:~] j06003% java test36 2 p1.num ==3000 3 p2.num ==3000 |
ソースコード
1 class test37{ 2 public static void main(String argv[]){ 3 Card c1 = new Card(); 4 Card c2 = new Card(); 5 Card c3 = c1; 6 c1.deposit = 1000; 7 c2.deposit = 2000; 8 c3.deposit = 3000; 9 int sum = c1.deposit + c2.deposit + c3.deposit; 10 System.out.println(sum); 11 } 12 } 13 14 class Card{ 15 int deposit; 16 } |
実行結果
1 [nw0603:~] j06003% java test37 2 8000 |
ソースコード
1 class test38{ 2 public static void main(String argv[]){ 3 Card1 c1 = new Card1(); 4 Card1 c2 = c1; 5 c1.deposit = 1000; 6 c2.deposit = 2000; 7 Bank.useCard1(c1); 8 Bank.useCard1(c2); 9 /*c1.depositとc2.depositの関係は?*/ 10 } 11 } 12 13 class Card1{ int deposit; } 14 class Bank{ 15 public static void useCard1(Card1 c ){ 16 c.deposit -= 500; 17 } 18 } |
実行結果
1 [nw0603:~] j06003% java test38 2 c1.deposit = 1000 3 c2.deposit = 1000 |