What is the result?
Given: public class MyClass { public static void main(String[] args) { String s = " Java Duke "; int len = s.trim().length(); System.out.print(len); } } What is the result? A. 8 B. 9 C. 11 D. 10 E. Compilation fails
Given: public class MyClass { public static void main(String[] args) { String s = " Java Duke "; int len = s.trim().length(); System.out.print(len); } } What is the result? A. 8 B. 9 C. 11 D. 10 E. Compilation fails
Given: public class App { // Insert code here System.out.print("Welcome to the world of Java"); } } Which two code fragments, when inserted independently at line // Insert code here, enable the program to execute and print the welcome message…
Given the code fragment: public class Test { public static void main(String[] args) { boolean isChecked = false; int arry[] = {1,3,5,7,8,9}; int index = arry.length; while ( <code1> ) { if (arry[index-1] % 2 ==0) { isChecked = true;…
Given: public class TestLoop { public static void main(String[] args) { int array[] = {0, 1, 2, 3, 4}; int key = 3; for (int pos = 0; pos < array.length; ++pos) { if (array[pos] == key) { break; }…
Given the code fragment: public class ForTest { public static void main(String[] args) { int[] array = {1, 2, 3}; for ( foo ) { } } Which three code fragments, when replaced individually for foo, enables the program to…
Given: abstract class A1 { public abstract void m1(); public void m2() { System.out.println("Green"); } } abstract class A2 extends A1 { public abstract void m3(); public void m1() { System.out.println("Cyan"); } public void m2() { System.out.println("Blue"); } } public…
Which two statements correctly describe checked exception? A. These are exceptional conditions that a well-written application should anticipate and recover from. B. These are exceptional conditions that are external to the application, and that the application usually cannot anticipate or…
Given: public class ColorTest { public static void main(String[] args) { String[] colors = {"red", "blue","green","yellow","maroon","cyan"}; int count = 0; for (String c : colors) { if (count >= 4) { break; } else { continue; } if (c.length() >=…
Given the code fragment: for (int ii = 0; ii < 3;ii++) { int count = 0; for (int jj = 3; jj > 0; jj–) { if (ii == jj) { ++count; break; } } System.out.print(count); continue; } What…
Given the code fragment: class Student { int rollnumber; String name; List cources = new ArrayList(); // insert code here public String toString() { return rollnumber + " : " + name + " : " + cources; } }…