Showing posts with label String Manupulation. Show all posts
Showing posts with label String Manupulation. Show all posts
Saturday, April 25, 2015
Saturday, April 18, 2015
Replacing Consonants
Code for Replacing Consonant With the Next Consonant in the Provided String.
import java.util.Scanner; //Scanner Class
public class StringMapOne{
static String alterString(String s) //Method to Alter the String
{
int n = s.length();
char[] ar = new char[n];
ar = s.toCharArray();
for(int i=0;i<n;i++)
{
switch(ar[i])
{
case 'b':
case 'c':
case 'd':
case 'f':
case 'g':
case 'h':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z': int c = (int)ar[i]; //Printing the Next Letter to Consonants
c = c+1;
char d = (char)c;
ar[i] = d;
break;
default : ar[i] = ar[i];
break;
}
}
String obj = new String(ar);
return obj.toUpperCase(); //Printing in Upper Case
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Program to Perform Opeation on String");
System.out.print("Enter the String:- \t");
String z = sc.next().toLowerCase();
String b = alterString(z); //Calling the Function
System.out.println("The Output is:- \t"+b);
}
}
Subscribe to:
Posts (Atom)