Select the correct answerWhat will be the output of the following Java program, if we run as “java Codetantra 4 7 9”? class Codetantra { public static void main(String [] args) { String [][] argument = new String[2][2]; int a; argument[0] = args; a = argument[0].length; for (int b = 0; b < a; b++) System.out.print(" " + argument[0][b]); } }Options4 04 44 0 94 7 9
Question
Select the correct answerWhat will be the output of the following Java program, if we run as “java Codetantra 4 7 9”? class Codetantra { public static void main(String [] args) { String [][] argument = new String[2][2]; int a; argument[0] = args; a = argument[0].length; for (int b = 0; b < a; b++) System.out.print(" " + argument[0][b]); } }Options4 04 44 0 94 7 9
Solution
The correct answer is "4 7 9".
Here's the step by step explanation:
-
The main method of the class Codetantra takes a String array as an argument. When we run the program as “java Codetantra 4 7 9”, the args array will contain ["4", "7", "9"].
-
A 2D String array 'argument' is created with size 2x2.
-
The first row of 'argument' is assigned the 'args' array. So, argument[0] now contains ["4", "7", "9"].
-
The variable 'a' is assigned the length of argument[0], which is 3.
-
A for loop runs from 0 to 'a' (0 to 3), and in each iteration, it prints the 'b'th element of argument[0].
-
So, it prints "4", "7", "9" with a space before each number. Hence, the output is "4 7 9".
Similar Questions
Select the correct answerWhat will be the output of the following Java code? class codetantra { public static void main(String args[]) { char a = 'A'; char b = 76; b++; a++; System.out.println(a + " " + b); } }OptionsC NB MD OA M
Select the correct answer What will be the output of the following Java code?class evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 8; n = arr[arr[n] / 4]; System.out.println(arr[n] / 4); } }Options1230
Select the correct answerWhat will be the output of the following Java program? class CT { public static void main(String args[]) { try { System.out.print("Codetantra" + " " + 1 / 0); } catch(ArithmeticException e) { System.out.print("World"); } } }OptionsCodetantraCodetantraWorldCodetantra WorldWorld
rrect answerWhat will be the output of the following Java code? class Name { public static void main(String args[]) { try { int ct1 = 0; int ct2 = 5; int ct3 = ct2 / ct1; System.out.print("Hello"); } catch(Exception e) { System.out.print("CodeTantra"); } } }
Select the correct answerWhat will be the output of the following Java statement?class output { public static void main(String args[]) { double ct1, ct2, ct3; ct1 = 3.0/0; ct2 = 0/4.0; ct3 = 0/0.0; System.out.println(ct1); System.out.println(ct2); System.out.println(ct3); } }OptionsNaN0.0Infinityall of the mentioned
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.