Sunday 30 November 2014

Program to remove a particular character from a sentence





public class SB

{
public static void main(String[] args) {

{
String test=null;
char remove = 0;
System.out.println("Enter the String");
test = new Scanner(System.in).nextLine();
System.out.println("Enter the Character to be removed");
remove=new Scanner(System.in).nextLine().charAt(0);
StringBuilder newstring =new StringBuilder();
for (int i = 0; i < test.length(); i++) {
if(remove==test.charAt(i))
{
continue;
}
newstring.append(test.charAt(i));
}
System.out.println(newstring);
}


}

}


You may like :
Difference between equals() and = =
Singleton Design Pattern
Other Programs in Java
Custom Exception in Java -Tutorial




No comments:

Post a Comment