hi i am facing some problem in my code please help me.
//code
public static void main(
String[] args) {
int charCounter=0;
int digCounter=0;
int spcCounter=0;
try{
File f = new File("E:\\abc.txt");
f.createNewFile();
FileWriter br = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(br);
bw.write("Arsaedf123");
bw.newLine();
bw.write("abcd");
bw.newLine();
bw.write("Ayaan");
for(int i=0;i<bw.length();i++){
char ch = bw.charAt(i);
if (Character.isLetter(ch)) {
charCounter++;
}
//
if(Character.isDigit(ch)){
digCounter++;
}
if(Character.isSpaceChar(ch)){
spcCounter++;
}
//
}
System.out.println("Characters="+charCounter);
System.out.println("digits="+digCounter);
System.out.println("space="+spcCounter);
bw.close();
}
catch (IOException e){
}
}
}
in the above program i am using for loop in that for loop how can i check that particular line contains any space or digits
please solve my problem.
Actually sir i am having a proble to count spaces and digits in a line
so i am using a for loop to check weather the given line is contain digits and spaces or not which are as follows
\\code
[java=code]
for(int i=0;i<bw.length();i++){
char ch = bw.charAt(i);
if (Character.isLetter(ch)) {
charCounter++;
}
//
if(Character.isDigit(ch)){
digCounter++;
}
if(Character.isSpaceChar(ch)){
spcCounter++;
}
//
[\code]