Computer Applications
Arrange the following java statements in the correct order of execution to accept values into the array a[]:
(i) a[i]=sc.nextInt( );
(ii) int a[]=new int[10];
(iii) Scanner sc=new Scanner(System.in);
(iv) for(i=0;i<10;i++)
- (i), (ii), (iii), (iv)
- (ii), (iii), (iv), (i)
- (iv), (iii), (ii), (i)
- (iii), (i), (iv), (ii)
Answer
(ii), (iii), (iv), (i)
Reason — First, the array a must be declared and initialized (int a[] = new int[10];). Then, the Scanner object sc is created to accept input (Scanner sc = new Scanner(System.in);). Next, a for loop (for(i=0; i < 10; i++)) is used to iterate over the array indices. Inside the loop, values are accepted from the user and stored in the array (a[i] = sc.nextInt();). This sequence ensures proper initialization and input handling.
The statements in the correct order of execution are as follows:
(ii) int a[]=new int[10];
(iii) Scanner sc=new Scanner(System.in);
(iv) for(i=0;i<10;i++)
(i) a[i]=sc.nextInt( );
Related Questions
The java statement System.out.println(x[x.length]) results in:
- logical error
- syntax error
- run time error
- no error
Which of the following is a valid array declaration statement to store the Gender of 80 employees [ 'M'-male, 'F'-female, 'T'-transgender ]?
- char gender = new char[80];
- char gender[] = new char[80];
- char gender[80];
- char gender[80] = new char[ ];
In the bubble sort technique, during each iteration of the inner loop, two adjacent elements are …………… and …………… .
(i) compared
(ii) swapped
(iii) selected
(iv) deleted- (i) and (ii)
- (ii) and (iii)
- (iii) and (iv)
- (ii) and (iv)
What is the highest index of any array with 100 elements?
- 100
- 101
- 99
- 98