The output of the following code is ________
String one = "Hello"; String two = "Hello"; if( one == two ) { System.out.println("equal"); } else { System.out.println("not equal"); }
not equal |
equal |
Code on't compile |
Answer: equal
The output of the following code is equal. So option 2 is correct.
The output of the following code is ________ String one = "Hello"; String two = "Hello";...
(a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) { System.out.println ("Hello"); x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) { sum = sum + i; i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...
List the output for the following lines of code (Hint: 4 lines of code should print): public class MPL3 { public static void main(String[] args) { String s1 = "Java isn't just for breakfast."; String s2 = "JAVA isn't just for breakfast."; String s3 = "A cup of java is a joy forever."; if (s3.compareToIgnoreCase(s1) < 0) { System.out.println("\"" + s3 + "\""); System.out.println("precedes"); System.out.println("\"" + s1 + "\""); System.out.println("in alphabetic ordering"); } else System.out.println("s3 does not precede s1."); }...
Fix 15 errors in the code below public class CallingMethodsInSameClass { string fName = Joe; string lName = Hasley; string fullName; public static void main(String[] args) { printOne() concatThem() } public static void printOne() { System.out.println(Hello World) public static void concatThem() { fullName = fName + “ “ + lName; if(fullName.equals(fName + lName){ system.out.println(“It’s a match! fullName is: “ + fullname”) } else ...
Question 2 1 point possble (graded) Consider the following code segment. String a- a0 if (a-0") else if (a"1") else if (a" else( System.out.printin("a is 0 System.out.printin("a is 1! System.out.println("a is al") System.out.println(a is something else!) Which of the following statements about the code segment is true? It produced "a is 0!" as output It produced "a is 1!" as output It produced "a is a!" as output It produced "a is something else!" as output It results in an...
need help with java questions
The following snippet of code would produce what outcome? public static void main(String 2 [] args) { int day = 5; switch (day) { case 1: System.out.println("Monday "); case 2: System.out.println("Tuesday "); case 3: System.out.println("Wednesday "); case 4: System.out.println("Thursday "); case 5: System.out.println("Friday "); case 6: System.out.println("Saturday "); case 7: System.out.println("Sunday "); break; default: System.out.println("Invalid Day "); } } Invalid Day Friday Saturday Sunday Invalid Day Friday Friday Saturday Sunday What will be the output...
Show the output of the following piece of code: public static void main(String[] args) { char x = 'a'; char y = 'c'; System.out.println(++x); System.out.println(y++); System.out.println(x - y); }
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() { super(); System.out.println(“B() called”);...
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() { super(); System.out.println(“B() called”); } public...
Consider the following code that repeats a C++ string three times. string a = "Hello"; string b = a + a + a; Suppose s is a C string, and t is declared as char t[100]; Write the equivalent code for C strings that stores the threefold repetition of s (or as much of it as will fit) into t. (C++)
When I try running this code in java, it doesn't work properly. The part where it should ask the user to write some string, where I would write in "one two three four" doesn't work, it says "bash: one: command not found" Please help fix. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); System.out.println("The arguments are:"); for(String element : args) { System.out.println("\t" + element); } } } Sample output: Hello World! The arguments are: ...