- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
public class q132 {
static int array[]= {10,20,30,40,50};
static int x=array.length;
public static void main(String[] args)
{
/*ans__()*/
}
static void ans_a()
{while(x>0)
{
x--;
System.out.print(array[x]);
}
}
static void ans_b()
{do
{
x--;
System.out.print(array[x]);
}while(x>=0);
}
static void ans_c()
{while(x>=0)
{
System.out.print(array[x]);
x--;
}
}
static void ans_d()
{do
{
System.out.print(array[x]);
x--;
}while(x>0);
}
static void ans_e()
{while(x>0)
{
System.out.print(array[--x]);
}
}
}
Which two code fragments can be independently insert at ans__ to
eable the code to print the element of the array in reverse order這題是要判斷哪個迴圈能列印出逆向的array[]數列 其中X的數是array[]數列的長度
因此在執行
while(x>=0)
{x--;}
或
do
{
x--;
}while(x>0);
時會超過數列長度,刪掉是(X>=0)的選項後便可發現,答案是A,E
留言
張貼留言