What is the output of this program?class Abc{public static void main(String[]args){String[] elements = { "for", "tea", "too" };String first = (elements.length > 0) ? elements[0]: null;}}Select one:Compilation errorAn exception is thrown at run timeThe variable first is set to elements[0].The variable first is set to null
Question
What is the output of this program?class Abc{public static void main(String[]args){String[] elements = { "for", "tea", "too" };String first = (elements.length > 0) ? elements[0]: null;}}Select one:Compilation errorAn exception is thrown at run timeThe variable first is set to elements[0].The variable first is set to null
Solution
The variable first is set to elements[0].
Similar Questions
Select the correct answerWhat will be the output of the following Java program? class Codetantra { public static void main(String[]args) { String[] elements = { "One", "two", "three" }; String first = (elements.length > 0) ? elements[0]: null; } }OptionsThe variable first is set to nullAn exception is thrown at run timeCompilation errorThe variable first is set to elements[0]
What is output of the following code:public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); }
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); }}
Consider the following program.public class Main { public static void main(String args[]) { String[] names = new String[2]; names[0] = "Alice"; names[1] = "Bob"; names[2] = "Charlie"; System.out.println(names[2]); }}Which of the following is an output of the above program? a. Charlie b. Bob c. Alice d. Compilation Error
What is the output of the following code :class MyClass {public static void main(String[] args) {int i=1,j=1;for (;i<3;i++){for(;j<4;j++);j++;System.out.print(i + j+" ");}}
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.