Menu
Topics Index
...
`

Code PointAt


If you need explanation Read this topic

If you need Answer Take test on this topic

Code PointAt
What will be the output of the following program?
public class Codepoint {
    public static void main(String args[]) {
        StringBuffer sub = new StringBuffer("Mango");
        int c = sub.codePointAt(2);
        System.out.println("Code point at given char: " + c);
        int d = sub.codePointBefore(2);
        System.out.println("Code point before char: " + d);
    }
}

A. Code point at given char: 111
Code point before char: 97
B. Code point at given char: 110
Code point before char: 96
C. Code point at given char: 110
Code point before char: 97
D. Compilation Error or Runtime Error
Topic: Additional StringBuffer Methods In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is C..here we have the StringBuffer class which is an mutable class means we can edit the content of this object...unlike strings if we edit the content than new instance will created...

here we created the StringBuffer by passing Mango String...
here we have 2 methods coidePoint()..which returns the Ascii value for the specified index...and codePointBefore() it will return ascii value of specified index -1...means if we pass 3 than it will give the ascii of 2..

Execution:here we are calling coidPoint() by passing the 2 means it is the index of n so ascii value of n is 110..next we are calling codePoitnBefore() by passing the 2 so here it will return the ascii value of char which is location 1..so here it will return 97 which is the ascii value of a

a-97 b-98....z-122
A-65,B-66,....Z90

Posted by Uday Kumar    2014-12-17 14:28:34


ans c.stringbuffer similar to string, but it can be modified and growable at run time.string Mango is stored in string buffer.this buffer object is accessed with codepointAt(2) This method returns int data type which corresponds to the the Unicode point at specified index .here index 2 we have 'n' so unicode of n get stored in c,sop prints c value 110,we can also call unicode as ascii value.thn codePointBefore(2) This method returns int data type which corresponds to the the Unicode point at before the specified index .so here before indx is 1 .unicode of a get stored in d,sop prints 97.codePointAt() this can access index 0 to length-1,codePointBefore() it can access 1 to length of string.

Posted by Maheshwari Natarajan    2014-12-17 18:12:50


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar, Maheshwari Natarajan,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-18 04:36:14


© meritcampus 2019

All Rights Reserved.

Open In App