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
Question
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
Solution
The output of the Java program will be 91.
Here's the step-by-step explanation:
-
The program starts with defining a class named "mainclass".
-
Inside this class, the main method is defined. This is the entry point of any Java application.
-
Inside the main method, a char variable 'a' is declared and initialized with the value 'Z'. In ASCII, the character 'Z' has a decimal value of 90.
-
The next line of code increments the value of 'a' by 1. So, 'a' now holds the character that comes after 'Z' in ASCII, which is '['. The ASCII value of '[' is 91.
-
The System.out.print((int)a) statement prints the integer value of 'a', which is now 91.
So, the output of the program is 91.
Similar Questions
What will be the output of the below program?public class Test { public static void main(String[] args) { char c = 65; System.out.println("c = " + c); }} Note : explain clearly in the answer
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
What will be the output of the following program?class string_class {public static void main(String args[]){String obj = "hello";String obj1 = "world"; String obj2 = obj;obj2 = " world";System.out.println(obj + " " + obj2); }}
e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}
What 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; int j; try { while((i = input1.read()) == (j = input2.read())) { System.out.print((char)i); } } catch (IOException e) { e.printStackTrace(); } } }A) abcB) abcdC) abcdeD) none of the mentioned
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.