faq 2 dimensional array questions and answers in java
(1)
public class ArrayDemo {
public static void main(String[] args) {
double arr[3];
arr[0]=2.1;
arr[1]=3.1;
arr[2]=4.1;
System.out.println(arr[1]+arr[2]);
}
}
What will be the output of above java program?
(a)7.2
(b) Any number greater than 7.2
(c) Any number less than 7.2
(d) Compiler error
Answer: (d)
(2)
public class ArrayDemo {
public static void main(String[] args) {
double arr[]=new double[5];
System.out.println(arr[1]*arr[2]);
}
}
What will be the output of above java program?
(a)0.0
(b)NaN
(c)Run time exception
(d) Compiler error
Answer: (a)
(3)
public class ArrayDemo {
public static void main(String[] args) {
double [] arr={1.D,2.D,3.D};
System.out.println(arr[3]);
}
}
What will be the output of above java program?
(a)3.0
(b)0.0
(c)Run time excepion
(d) Compiler error
Answer: (c)
(4)
public class ArrayDemo {
public static void main(String[] args) {
long arr[][]={10L,20L,30L,40L};
System.out.println(arr[1][1]);
}
}
What will be the output of above java program?
(a)10
(b)30
(c)40
(d) Compiler error
Answer: (d)
(5)
public class ArrayDemo {
public static void main(String[] args) {
long arr[][]={{10l},{20l,30l,40l,50l}};
System.out.println(arr[1][2]);
}
}
What will be the output of above java program?
(a)0
(b)40
(c)30
(d) Compiler error
Answer: (b)
(6)
public class ArrayDemo {
public static void main(String[] args) {
long [][]arr=new long [2][];
arr[0]=new long[2];
arr[1]=new long[3];
arr[0][1]=5L;
System.out.println(arr[0][1]);
}
}
What will be the output of above java program?
(a)5
(b)5l
(c)5L
(d) Compiler error
Answer: (a)
(6)
public class ArrayDemo {
public static void main(String[] args) {
long [][]arr=new long [2][];
arr[0]=new int[2];
arr[1]=new int[3];
arr[0][1]=015L;
System.out.println(arr[0][1]);
}
}
What will be the output of above java program?
(a)13
(b)15
(c)0
(d) Compiler error
Answer :( d)
(7)
public class ArrayDemo {
public static void main(String[] args) {
if((int)Math.sqrt(2)==1)
System.out.println("equal(+)");
if((int)Math.sqrt(2)==-1)
System.out.println("equal(-)");
}
}
What will be the output of above java program?
(a) equal(+)
(b) equal(-)
(c) equal(+)
equal(-)
(d)Compiler error
Answer: (a)
(8)
public class ArrayDemo {
public static void main(String[] args) {
int []arr,a;
arr=new int[2];
a=011;
arr[0]=arr[1]=a;
System.out.print(arr[0]+arr[1]);
}
}
What will be the output of above java program?
(a)22
(b)18
(c)022
(d)Compiler error
Answer: (d)
(9)
public class ArrayDemo {
public static void main(String[] args) {
int [] arr1,arr2;
arr1=new int[1];
arr2=new int[2];
arr1[0]='\n';
arr2[0]='a';
System.out.print(arr2[0]%arr1[0]);
}
}
What will be the output of above java program?
(a)6
(b)7
(c)0
(d)Compiler error
Answer: (d)
Java questions of data types and answer
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
Java questions of data types and answer
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
1 comment:
Nice collection. I like it.
Post a Comment