Q: The enhanced for loop is only used with arrays and collections for
A: Retrieving elements from array or collection
Q: Predict the output of the following code:
public class Main
{
public static void main(String[] args)
{
int arr[] = {'a','b','c','d','e'};
System.out.print(arr);
}
}
A: Garbage Value
Q: What will be the output for the following code?
public class Main
{
public static void main(String[] args)
{
int arr[] = new int [5];
System.out.print(arr);
}
}
A: Garbage value
Q: Predict the output of the following code:
public class Main
{
public static void main(String[] args) {
int arr[] = {'a','b','c','d','e'};
for(int i = 0 ; i<5; i++)
{
System.out.print((char)arr[i] + " ");
}
}
}
A: a b c d e
Q: Predict the output for the following code:
public class Main
{
public static void main(String[] args)
{
int arr[] = {1,2,3,4,5};
int count = 0;
for(int i = 0 ; i<5; i++ )
{
if(arr[i]%2==0)
count++;
}
System.out.print(count);
}
}
A: 2
Q: Which of the below statements can be said to be the disadvantages of arrays?
A: All of the above mentioned.
Q: Predict the output of the following code.
public class Main
{
public static void main(String[] args)
{
int arr[] = {'a','b','c','d','e'};
for(int i = 0 ; i<5; i++)
{
System.out.print(arr[i] + " ");
}
}
}
A: 97 98 99 100 101
Q: What will be the output of the following program?
class Main {
public static void main(String[] args) {
int arr[] = {1,2,3,4,5};
int count = 0;
for(int i = 0 ; i<5; i++) {
if(arr[i]%2==0)
arr[i] *= 2;
System.out.print(arr[i]);
}
}
}
A: 14385
Q: What will be the output of the following program?
public class Main {
public static void main(String[] args) {
int arr[] = {1,2,3,4,5};
for(int i = 0 ; i<5; ) {
System.out.print(arr[i]);
}
}
}
A: None of the mentioned options
Q: Arrays are a group of similar types of datatypes.
A: True
Q: What will be the output for the following code?
class Main
{
public static void main(String args[])
{
int a1[] = new int[10];
int a2[] = {3, 5, 7, 1, 8, 99, 44, -10};
System.out.println("length of a1 is " + a1.length);
System.out.println("length of a2 is " + a2.length);
}
}
A: length of a1 is 10length of a2 is 8
Q: How many of the following are legal declarations? float[] lion = new float[]; float[] tiger = new float[1]; float[] bear = new[] float; float[] ohMy = new[1] float;
A: 1
Q: What will be the output of the following program?
class Main {
public static void main(String[] args) {
int arr[] = {1,2,3,4,5};
for(int i = 0 ; i<5; i++) {
System.out.print(arr[i++]);
}
}
}
A: 135
Q: What will happen when an array is created using a new keyword?
A: All its elements are automatically initialized to their default values
Q: What will be the output of the following program?
class Main {
boolean[] array = new boolean[3];
int count = 0;
void set(boolean[] arr, int x) {
arr[x] = true;
count++;
}
void func() {
if(array[0] && array[++count - 2] | array [count - 1])
count++;
System.out.println("count = " + count);
}
public static void main(String[] args) {
Main object = new Main();
object.set(object.array, 0);
object.set(object.array, 1);
object.func();
}
}
A: count = 4