public String removeNumbersInString(String str) {
String temp = "";
String regexp = "^[0-9]";
Pattern pattern = Pattern.compile(regexp);
Matcher matcher;
if(!str.isEmpty()){
for (int i = 0; i < str.length(); i++) {
matcher = pattern.matcher(str.charAt(i) + "");
if (!matcher.matches()) {
temp = temp + str.charAt(i) + "";
}
}}
System.out.println("" + temp);
return temp;
}
Java programs for beginners, list of programs in java on various topics, interesting programs in java. Java programs on various topics
Wednesday, March 19, 2014
Remove Numbers in String - Java Program
Remove String in Numbers-Java Program
public String removeStringInNumbers(String str) {
String temp = "";
String regexp = "^[a-zA-Z]";
Pattern pattern = Pattern.compile(regexp);
Matcher matcher;
if(!str.isEmpty()){
for (int i = 0; i < str.length(); i++) {
matcher = pattern.matcher(str.charAt(i) + "");
if (!matcher.matches()) {
temp = temp + str.charAt(i) + "";
}
}}
System.out.println("" + temp);
return temp;
}
Saturday, March 1, 2014
Write an example that counts the number of times a particular character, such as e, appears in a file. The character can be specified at the command line.
import java.io.BufferedInputStream;
import java.io.FileInputStream;
class GetOccurrences{
public static void main(String args[])
{
try{
FileInputStream fis=new FileInputStream("C:\\Users\\SAN-MCA-ME-MTECH-MS\\Documents\\SAN\\Temp.txt");
BufferedInputStream bis=new BufferedInputStream(fis);
int i;
int occurs=0;
while((i=bis.read())!=-1)
{
char a=(char)i;
if(a==args[0].charAt(0))
{
occurs++;
}
}
System.out.println("Letter e is "+occurs+" of times repeated in the file");
}catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
Subscribe to:
Posts (Atom)