ct 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); }}Optionsfrofor
Question
ct 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); }}Optionsfrofor
Solution
The output of the Java program will be "for". The program creates a character array with the elements 'f', 'o', 'r' and then creates a new String object from this array. The System.out.println(s) statement then prints this string to the console.
Similar Questions
Consider the given code: class String_demo { public static void main(String args[]) { char arr[] = {'Q','W','E','R','T','Y}; } }Which among the following option will print QWERTYA) System.out.println(arr);B) System.out.println(arr.toString());C) new String(arr); System.out.println(str);D) System.out.println(Arrays.toString(arr));
ect the correct answerWhat will be the output of the following Java program?import java.io.*;class Chararrayinput { public static void main(String[] args) { String obj = "abcdefgh"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 1, 4); int i, j; try { while ((i = input1.read()) == (j = input2.read())) { System.out.print((char) i); } } catch (IOException e) { e.printStackTrace(); } }}
the correct answerWhat will be the output of the following Java program? class mainclass { public static void main(String args[]) { char a = 'Z'; a++; System.out.print((int)a); } }Options9112290123
What 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
elect the correct answerWhat will be the output of the following Java code?class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 3; ++i) { array_variable[i] = 'R'; System.out.print(array_variable[i] + ""); } } }OptionsPQR0 1 2 3 4 51 2 3 4 5 6 7 8 9 10RRR
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.