TEST 4

1. In java Array are :

 

 
 
 
 

2. Which one of the following is a valid statement?

 
 
 
 

3.

What is the result of compiling and running the following code?
public class Test{
        public static void main(String[] args){
                int[] a = new int[0];
                System.out.print(a.length);
        }
}

 

 
 
 
 

4. Which of these is an incorrect array declaration?

 
 
 
 

5. What will be the output of following code ?

    int arr[] = new int [5];
    System.out.print(arr);
 
 
 
 

6. Which of these is an incorrect Statement?

 
 
 
 

7.

How many of the following are legal declarations?
[]double lion;
double[] tiger;
double bear[];

 
 
 
 

8.

How do you determine the number of elements in an array?

int buses[] = new int[5];
 
 
 
 

9.

 Which of the following create an empty two-dimensional array with dimensions 2×2?
 
 
 
 

10. What does this code output ?

String[] nums = new String[] { "1", "9", "10" };
Arrays.sort(nums);
System.out.println(Arrays.toString(nums));
 
 
 
 

11.

How many of the following are legal declarations?
1.float[] lion = new float[];
2.float[] tiger = new float[1];
3.float[] bear = new[] float;
4.float[] cat = new[1] float;
 
 
 
 

12. size of an array we can declared in long data type?

 
 
 

13. size of an array we can declared in long data type?

 
 
 

14.

What does the following output?
String[] os = new String[] { "Mac", "Linux", "Windows" };
Arrays.sort(os);
System.out.println(Arrays.binarySearch(os, "Mac"));
 
 
 
 

15.

  What is the output of the following code fragments?
int [ ] fun = new int [5];
     fun[0] = 1;
     fun[1] = 2;
     fun[2] = 3;
     fun[3] = 4;
     fun[4] = 5;
     int j = 3;
     System.out.println(fun[ j-1]) ;
 
 
 
 

16.

What is the output of the following code fragment?
     int [ ] odd = {1, 3, 5, 7, 9, 11 };
System.out.println( odd[0] + ”  ” + odd[3] ) ;
 
 
 
 

17. Which of these is necessary to specify at time of array initialization?

 
 
 
 

18. What will be the output following code

  1.     class array_output
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             int array_variable [] = new int[10];
  6. 	    for (int i = 0; i < 10; ++i)
  7.             {
  8.                 array_variable[i] = i;
  9.                 System.out.print(array_variable[i] + " ");
  10.                 i++;
  11.             }
         }
  12.     }
 
 
 
 

19. Determine the output

public class array

{

public static void main(String args[])

{

int []x={ 1,2,3,4};

int []y=x;

x=new int[2];

for (int i=0; i<x.lenght;i++)

System.out.println(y[i] + “”);

}

}

 
 
 
 

20. When you pass an array to a method , the method receives :

 

 
 
 
 

21.

What does the following method do?
     public static void numbers (int [ ] num)
    {
          for(int x = 1; x < num.length; x++)
              num[x] = num[0];
     }      
 
 
 
 

22.

19.  What is the length of this array?
       double[ ] stuff = {1.5,  2.5,  3.5,  4.5,  5.5,  6.5};
 
 
 
 

23. What is the output of the following code fragmented ?

        int [ ] array = { 2, 4, 6, 8, 1, 3, 5, 7};
int george = 0;
for (int i = 0; i < array.length; i++)
george += array[i];
System.out.print(george);
 
 
 
 

24.

Which of the following is advantage of java array?
 
 
 
 

25. What will be the output

class Main
{
public static void main(String args[])
 {
  int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int n = 6;
  n = arr[arr[n] / 2];
  System.out.print(n);
 } 
}
 
 
 
 

26.

Array is a collection of ________.
 
 
 
 

27.

Array can allocate __________.
 
 
 
 

28. Which of these is an incorrect Statement?

 
 
 
 

29.

16.  What is the output from the following code fragment?
       String [ ] name = { "Joe", "Sue", "Tom", "Jill", "Patty"};
       for (int i = 0; i < name.length; i = i + 2)
           System.out.print(name[i] + " ");
 
 
 
 

30. What is the output of the program after compile and Run :

class Mango

{

public static void main()

{

System,out,println(“Mango”);

}

}

 
 
 
 

31. When program will be compiled then what will be the part of output,select any one from the followings:

public class less

{

public static void main(String p[])

{

for(int m=0;m<3;m++)

{

for(int n=3;n>=0;n–)

{

if(m==n)

break;

System.out.println(m+” “+n);

}

}

}

}

 
 
 
 

32. When program will be compiled then what will the part of output ,select any one from the followings:

public class count

{

public static void main(String E[])

{

for(int m=0;m<3;m++)

{

for(int n=3;n>0;n–)

{

if(m==n)

continue;

System.out.println(m+” “+n);

}

}

}

}

 
 
 
 

33. What will print on screen when following program compiled?

public class myprint

{

public static void main(String K[])

{

int m=0;

boolean b2=true;

boolean b3=false;

int b4=(b2&&((m++)==0));

b4=(b3&&((m++)==0));

System.out.println(m);

}

}

 
 
 
 
 

34. What is the output of the following program ?

class OK

{

public static void main(String B[])

{

int a,b,c,d=0;

c=d++;

b=++c;

a=b++;

System.out.println(a);

}

}

 
 
 
 

35. When following will be compiled, then at which line error will be notice :

public class castPrint

{

public static void main(String a[])

{

char C;

int K;

C=’A’;

K=C;

C=K+10;

++C;

}

}

 
 
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *