Computer Applications
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])?
Java Arrays
3 Likes
Answer
(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)
Output
true
Explanation
- The element
ch[4]contains the character '7'. - The method
Character.isDigit('7')returns true because '7' is a numeric digit.
Answered By
1 Like
Related Questions
Consider the given array and answer the questions given below:
int z[ ] [ ] = { {2, 3, 4}, {5, 1, 2}, {7, 9, 3}};(a) What is the order of the array z[ ][ ]?
(b) What is the value in z[2][0]?
Give the output of the following:
(a) "ROSE".compareTo("ROJA")
(b) "DEDICATE".replace('D', 'L')
class perform { int m; String name; perform(int x, String y) { m=x; name=y; } void print() { System.out.print(name + " " + m); } public static void main() { perform ob1=new perform(95 , "Xavier"); ob1.print(); } }(a) Give the output of the code given above.
(b) Name the type of the constructor used.
Define a class with following specifications.
class name: Hotel
Member variables:
String name – stores name of customer name
long mobno – stores mobile number
int days – stores number of days customer stayed in hotel
int bill – stores customer billMember method:
void input() – input values using Scanner class methods only
void charge() – calculate bill as per the following criteriadays charge/day first 3 days 1000 Rs/ day next 4 days 900 Rs/day > 7 days 800 Rs/day bill = bill + gst (18% of bill)
void print() - Display customer name, mobile number and bill.
Invoke all the above methods in main method with the help of an object.