elect the correct answerPredict the output ?class Test { public static void main(String args[]) { int arr[] = new int[2]; System.out.println(arr[0]); System.out.println(arr[1]); }}OptionsCompiler Errorgarbage valuegarbage value00Exception
Question
elect the correct answerPredict the output ?class Test { public static void main(String args[]) { int arr[] = new int[2]; System.out.println(arr[0]); System.out.println(arr[1]); }}OptionsCompiler Errorgarbage valuegarbage value00Exception
Solution
The correct answer is "00".
In Java, when you create an array, it is automatically initialized with default values. For an array of integers, the default value is 0. So, when you print arr[0] and arr[1], it will print 0 for both.
Similar Questions
Select the correct answerPredict the output of following Java program.?class CT { public static void main(String args[]) { int a; System.out.println(a); } } Optionscompiler errorgarbage value0runtime error
What is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}OptionsCompiler Error30Garbage value0
Select the correct answerWhat is the output of the following program?public class Test{ public static void main(String []args){ int i = 0; for(i = 0; i < 10; i++){ continue; } System.out.println(i); }}OptionsCompilation error0109
Analyze the following code: public class Test { public static void main(String argv[]) { System.out.println("argv.length is " + argv.length); } } Group of answer choicesThe program has a compile error because String argv[] is wrong and it should be replaced by String args[].If you run this program without passing any arguments, the program will have a runtime error because argv is null.If you run this program without passing any arguments, the program will display argv.length is 0.
Determine the output:public class A { public static void main(String argv[]){ int ary[]=new int[]{1,2,3}; System.out.println(ary[1]); }}Select one:a.2b.1c.Compilation Error:incorrect syntax
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.