1(ix)
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);:
- (a)65
- (b)130
- (c)'A'
- (d)0
Show SolutionHide Solution↓
130
Reason — The given array is:
char ch[] = {'A', 'E', 'I', 'O', 'U'};
Step-by-Step Execution:
1. ch[0]:
- The element at index
0of the array is 'A'.
2. Character Multiplication in Java:
- In Java, a
charis 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.