Menu
Topics Index
...
`

StringFunctions


If you need explanation Read this topic

If you need Answer Take test on this topic

StringFunctions
What will be the output of the following program?
public class RemoveChar
{
    public static void main(String args[])
    {
        String str = "Good Day.\n This is java program.";
        System.out.println(removeCharAt(str, 9));
    }
    public static String removeCharAt(String s, int pos)
    {
        return s.substring(0, pos) + s.substring(pos + 1);
    }
}

A. Good Day. 
This is java program.
B. Good Day. This is java program.
C. Good Day.
 This is java program.
D. Compilation Error
E. Runtime Error
Topic: Java String substring() method - substring 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 B..here we have the Strings concept..we create String using the literal so this content will store in the String poll where duplicates are not allowed..we devalop our own method named with the removeCharAt() this method is taking the 2 arg(String,Pos).
Execution:

in this method we are removing the char at specified postion..
(Spliting the string into 2 parts)

* 0 to till the specified position
*pos+1 to till the end
combining these both strings and returning so char at specified pos will remove

substring() this will return the string within specified range,if we pass single arg than it will return the string from that pos to till the end

Posted by Uday Kumar    2015-01-08 15:28:29


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Shashanka Mogaliraju. 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    2015-01-09 04:09:54


© meritcampus 2019

All Rights Reserved.

Open In App