堅持到底
2007-02-19 04:21:13 UTC
第一題:
class A extends Thread{
String[] sa;
public A(String[] sa){this.sa =sa}
public void run(){
synchronized (sa){
while(!sa[0].equals("Done")){
try{sa.wait();} catch(InterruptedException ie){}
}}
system.out.print(sa[1]+sa[2]+sa[3]);
}}
class B {
private static String[] sa=new String[]{"Not Done","X","Y","Z"};
public static void main(String[] args){
Thread t1=new A(sa);t1.start();
synchronized(sa){
sa[0] = "Done"
sa[1] = "A"; sa[2] = "B"; sa[3] = "C";
sa.notify();
}}}
What is the result of attempting to compile and run the program? Why?
(A)prints:XYZ
(B)prints:AYZ
(C)prints:ABZ
(D)prints:ABC
(E)Compile-time error
(f)Run-time error
(g)None of the above
請問這題要選哪個答案呢,我是覺得D,印出ABC,不曉得對不對
小弟對於java不熟悉,對C比較懂,也順便想問板上的大大
java語言的編輯器要去哪下載呢,就是能像DEV C++一樣可以寫C的應用程式,
感謝各位了 Orz
第二題
class MWC201{
public static viod main(String[] args){
int[][] a1 ={{1,2,3},{4,5,6},{7,8,9,10}};
System.out.print(a1[0][2]+","+a1[1][0]+","+a1[2][1]");
}}
What is the result of attempting to compile and run the program? Why?
(A)prints:3,4,8
(B)prints:7,2,6
(C)Compile-time error
(D)Run-time error
(E)None of the above
這題小弟覺得是A印出3,4,8,不曉得對不對,我是純粹用C語言的陣列觀念去看的
請各位前輩指教了
感謝再感謝....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.228.152.75
class A extends Thread{
String[] sa;
public A(String[] sa){this.sa =sa}
public void run(){
synchronized (sa){
while(!sa[0].equals("Done")){
try{sa.wait();} catch(InterruptedException ie){}
}}
system.out.print(sa[1]+sa[2]+sa[3]);
}}
class B {
private static String[] sa=new String[]{"Not Done","X","Y","Z"};
public static void main(String[] args){
Thread t1=new A(sa);t1.start();
synchronized(sa){
sa[0] = "Done"
sa[1] = "A"; sa[2] = "B"; sa[3] = "C";
sa.notify();
}}}
What is the result of attempting to compile and run the program? Why?
(A)prints:XYZ
(B)prints:AYZ
(C)prints:ABZ
(D)prints:ABC
(E)Compile-time error
(f)Run-time error
(g)None of the above
請問這題要選哪個答案呢,我是覺得D,印出ABC,不曉得對不對
小弟對於java不熟悉,對C比較懂,也順便想問板上的大大
java語言的編輯器要去哪下載呢,就是能像DEV C++一樣可以寫C的應用程式,
感謝各位了 Orz
第二題
class MWC201{
public static viod main(String[] args){
int[][] a1 ={{1,2,3},{4,5,6},{7,8,9,10}};
System.out.print(a1[0][2]+","+a1[1][0]+","+a1[2][1]");
}}
What is the result of attempting to compile and run the program? Why?
(A)prints:3,4,8
(B)prints:7,2,6
(C)Compile-time error
(D)Run-time error
(E)None of the above
這題小弟覺得是A印出3,4,8,不曉得對不對,我是純粹用C語言的陣列觀念去看的
請各位前輩指教了
感謝再感謝....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.228.152.75