No student devices needed. Know more
27 questions
程式語言一般支援算術、關係、邏輯等多種運算子(Operators),而這些運算子會具有優先順序。下列有關於Java或Objective-C運算子的優先順序的排序(由高到低),何者是正確的?
+ == &&
&& == +
== + &&
+ && ==
上列Java程式碼的執行結果為何?
*
**
***
****
下列Java程式碼執行後,會顯示為多少?
int x = 0; int y = 10; while (x < 5) { y--; ++x; } ; System.out.print(x + "," + y);
5,5
5,6
6,6
6,5
下列Java程式碼執行後,結果為何?
int a =2; int b =3;
b=(a)+(b++);
System.out.print (b);
5
6
7
8
關於以下程式片段,執行後之結果:
int v1 = 100;
double v2,v3;
v2 = v1/3;
v3 = (double)v1/3;
下列敘述何者正確?
v2之值(小數取二位)為33.00 且 v3之值(小數取二位)為33.33
v2之值(小數取二位)為33.33 且 v3之值(小數取二位)為33.33
v2之值(小數取二位)為33.00 且 v3之值(小數取二位)為33.00
v2之值(小數取二位)為33.33 且 v3之值(小數取二位)為33.00
下列何者的結果,與其他三個選項不同?
int a = 7, b; b = a++; print b;
int a = 7, b; b = ++a; print b;
int a = 88, b; b = a / 10; print b;
int a = 88, b; b = a % 10; print b;
關於以下程式片段,執行後之結果: int v1 = 100; int v2 = --v1;
下列敘述何者正確?
v1之值為100 且 v2之值為99
v1之值為99 且 v2之值為100
v1之值為100 且 v2之值為100
v1之值為99 且 v2之值為99
程式語言支援「運算式」(Expressions)以產生運算結果。下列Java或Objective-C的運算式執行結果何者是正確的?
int v1 = 10;
int v2 = v1*2;
int v3 = v1++-19/--v2;
v1之值為11 且 v2之值為20 且 v3之值為9
v1之值為11 且 v2之值為19 且 v3之值為9
v1之值為10 且 v2之值為20 且 v3之值為10
v1之值為10 且 v2之值為19 且 v3之值為10
程式語言支援運算子 (Operators)搭配運算元 (Operands)組成運算式(Expressions)以執行相關運算作業。下列Java或Objective-C程式片段執行後之結果何者為正確?
int v1 = 100;
int v2 = v1++;
v1之值為101 且 v2之值為101
v1之值為100 且 v2之值為100
v1之值為101 且 v2之值為100
v1之值為100 且 v2之值為101
關於以下程式片段:
int[] x= {2,4,18};
int r=0;
for(int i:x)
r+=i;
請問r等於多少?
6
3
24
18
以下程式執行結果,何者正確?
int total = 0,i,j;
for(i=0;i<3;i++)
for(j=0;j<i;j++)
total += j;
total之值為1
total之值為2
total之值為3
total之值為4
public static void main(String[] args) {
int i = 0;
for (int j = 0; j < 4; j++) i += 2;
System.out.println(i); }
請問執行結果為何?
0
4
6
8
public static void main(String[] args) {
int count = 2;
if(count > 0)
System.out.println("A");
System.out.println("B");
else System.out.println("C"); }
請問執行結果為何?
ABC
AB
C
Compilation fails(編譯錯誤)
public class A{
protect int methodA(int x){return 0;}
}
class B extends A{ //在此插入程式碼
}
下列程式碼各別插入於class B中,共有幾行可正確編譯?
public int methodA(int x){return 1;}
private int methodA(int x){return 0;}
protected int methodA(int x, int y){return 1;}
public String methodA(String x){return "A";}
1
2
3
4
請問下列程式碼執行後,變數count的值為何?
int count=0;
for(int i=1;i<=5;i++)
count=count+i/2;
0
15
7.5
6
int[] x= {2,4,18};
int r=0;
for(int i=0;i<=x.length;i++)
r+=x[i];
請問如果在螢幕上輸出r,則會在螢幕上看到什麼?
6
3
24
錯誤訊息
請問下列程式碼執行後,變數count的值為何?
int count=0;
for(int i=1;i<=5;i++)
count=count+i%3;
4
5
6
7
public class A {
public int a = 123; }
public class B extends A {
public int a = 456; }
如果執行下列程式碼:
B x = new B();
System.out.println( String.valueOf(x.a));
則螢幕上會看到下列何者?
123
456
123,456
456,123
下列程式碼執行完後,變數c的值為何?
int a=7,b=33;
int c=b/a+b%a;
4
5
7
9
public class MyClass {
public int m1( int p )
{
System.out.println("123");
}
public void m1( String p )
{
System.out.println("456");
}
}
如果執行以下程式:
(new MyClass()).m1("789");
螢幕上會看到下列何者?
123
456
789
編譯錯誤
public static void main(String[] args) {
int a = 4, b = 0;
switch (a) {
case 2:
b += 2;
case 4:
b += 3;
default:
b += 5;
case 0:
b += 4;
break;
case 6:
b += 1;
}
System.out.println("b = " + b);
}
請問執行這段程式之後,b的值為多少?
b = 13
b = 3
b = 8
b = 12
請問下列程式碼執行後,變數x的值為何?
int n=5,x=0;
switch(n) {
case 0:
x=x+1;;
case 5:
x=x+2;;
case 10:
x=x+3;
break;
default:
x=x+4;
}
3
5
6
9
請問下列哪個選項和以下的布林表示法完全一樣?
!(X==1 && Y==2 && Z==3)
!(X==1) && !(Y==2) && !(Z==3)
X!=1 && Y!=2 && Z!=3
X!=1 || Y!=2 || Z!=3
!(X==1 || Y==2 || Z==3)
閏年的規則為:「西元年逢4的倍數為閏年,但在這之中為100的倍數不為閏年,但400的倍數又為閏年。」,現有一個整數變數為 year,代表西元年的數字。請問下列選項何者可以精確表示閏年的條件?
year%4==0 && year%100!=0 && year%400==0
year%400==0 || year%100!=0 || year%4==0
year%4==0 || (year%100!=0 && year%400==0)
year%400==0 || (year%100!=0 && year%4==0)
請問下列程式碼執行後,輸出的結果為何?
String s1 = "Tom";
String s2 = "Tom";
String s3 = new String("Tom");
System.out.println(s1 == s2);
System.out.println(s2 == s3);
System.out.println(s1.equals(s3));
true true true
true false true
true true false
1 1 1
請問下列程式碼執行後,輸出的結果為何?
public static void main(String[] args) {
Integer i = args[0];
int j = 12;
System.out.println("It is " + (j==i) + " that j==i.");
}
It is true that j==i.
It is false that j==i.
出現Exception
編譯錯誤
public class A {
public void m1( )
{
System.out.println( "123");
}
}
public class B extends A {
public void m1( )
{
System.out.println( "456");
}
}
請問如果執行下列程式碼:
A x = new B();
x.m1();請問螢幕上會看到下列何者?
123
456
789
編譯錯誤
Explore all questions with a free account