I want to know how to do I check my sub string if it is a numerical value or if it is just words.
For example, if my substring d=150.63
I have done some research and I've found Character.is Digit()
, but it is not working. Below is the code I have made so far.
import java.util.*;
import java.io.*;
public class Prac34 {
private Scanner x;
public void openFile(){
try{
x=new Scanner(new File("sales.txt"));
}
catch (Exception e){
System.out.println("could not find file");
}
}
public void readFile(){
//int count=0;
double total=0;
while(x.hasNext()){
String a=x.nextLine();
int v=a.length();
int b=a.indexOf(':');
String c= a.substring(0,(b+1));
String d=a.substring((b+1),v);
double e= Double.parseDouble(d);
if (Character.isDigit(d)) {
total=total+e;
}
System.out.println(c);
System.out.println(d);
}
}
public void closeFile(){
x.close();
}
}