Computer Applications
Consider the array given below:
char ch[] = {'A','E','I','O', 'U'};
Write the output of the following statements:
System.out.println(ch[0]*2);:
- 65
- 130
- 'A'
- 0
Answer
130
Reason — The given array is:
char ch[] = {'A', 'E', 'I', 'O', 'U'};
Step-by-Step Execution:
1. ch[0]
:
- The element at index
0
of the array is 'A'.
2. Character Multiplication in Java:
- In Java, a
char
is treated as a numeric value based on its ASCII code when used in arithmetic operations. - The ASCII value of 'A' is 65.
3. ch[0] * 2
:
- Substituting
ch[0]
with its ASCII value:
65 * 2 = 130
4. Output:
System.out.println(ch[0] * 2);
will print 130.
Related Questions
Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)
Which of the following is not true with regards to a switch statement?
- checks for an equality between the input and the case labels
- supports floating point constants
- break is used to exit from the switch block
- case labels are unique
To execute a loop 10 times, which of the following is correct?
- for (int i=11;i<=30;i+=2)
- for (int i=11;i<=30;i+=3)
- for (int i=11;i<20;i++)
- for (int i=11;i<=21;i++)
A single dimensional array has 50 elements, which of the following is the correct statement to initialize the last element to 100.
- x[51]=100
- x[48]=100
- x[49]=100
- x[50]=100