Select the correct answerWhat will be the output of the following Java program?import java.lang.System; class Output { public static void main(String args[]) { byte a[] = { 65, 66, 67, 68, 69, 70 }; byte b[] = { 71, 72, 73, 74, 75, 76 }; System.arraycopy(a, 0, b, 3, a.length - 3); System.out.print(new String(a) + " " + new String(b)); } }OptionsOPQRST UVWXYZOPQRST OPQRSTOPQRST UVWOPQUVWOPQ UVWOPQ
Question
Select the correct answerWhat will be the output of the following Java program?import java.lang.System; class Output { public static void main(String args[]) { byte a[] = { 65, 66, 67, 68, 69, 70 }; byte b[] = { 71, 72, 73, 74, 75, 76 }; System.arraycopy(a, 0, b, 3, a.length - 3); System.out.print(new String(a) + " " + new String(b)); } }OptionsOPQRST UVWXYZOPQRST OPQRSTOPQRST UVWOPQUVWOPQ UVWOPQ
Solution
The correct answer is "OPQRST UVWOPQ".
Here's the step by step explanation:
-
The byte arrays
aandbare initialized with ASCII values ranging from 65 to 76. When these values are converted to characters,abecomes "OPQRST" andbbecomes "UVWXYZ". -
The
System.arraycopymethod is called withaas the source array, 0 as the source position,bas the destination array, 3 as the destination position, anda.length - 3as the length. This means that the last three elements ofa("OPQ") are copied intob, starting at the fourth position. -
The
System.out.printstatement prints the new strings formed fromaandb, separated by a space. Sinceahas not been modified, it still prints as "OPQRST". However,bhas been modified to "UVWOPQ" due to the array copy operation.
So, the output of the program is "OPQRST UVWOPQ".
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 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
Select the correct answerWhat will be the output of the following Java program?class String_demo { public static void main(String args[]) { char chars[] = {'f', 'o', 'r'}; String s = new String(chars); System.out.println(s); }}Optionsfrforo
Select the correct answerWhat will be the output of the following Java program?class output_odd { public static void main(String args[]) { int p = 2; int q = 0; for ( ; q < 8; ++q) { if (q % p == 0) continue; else if (q == 6) break; else System.out.print(q + " "); } } }Options1 3 5 7 91 3 5 71 2 3 4 5 6 7 8 92 4 6 8
What will be the output of the following Java program? package pkg; class output {public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); s1.setCharAt(1, x); System.out.println(s1); } }
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.