2(ix)
Consider the following array and answer the questions given below:
char ch [ ] = { ‘A’, ‘%’, ‘y’, ‘@’, ‘7’, ‘p’};
(a) How many bytes does the array occupy?
(b) What is the output of the statement Character.isDigit(ch[4])?
Show SolutionHide Solution↓
(a) In Java, each element of type char occupies 2 bytes of memory. The given array has 6 elements, therefore:
Total memory = 6 × 2 = 12 bytes.
(b)
true
- The element
ch[4]contains the character '7'. - The method
Character.isDigit('7')returns true because '7' is a numeric digit.