I coded something in Java looks what was imputed as string and then to convert that string into a double or an int IF there is a decimal (period) found. In my code it always jumps out of the loop and prints "no numbers found". Why is that? What is wrong.
My code:
//check if its actually numbers
if(leftSide.matches("[0-9]+") && rightSide.matches("[0-9]+")){
System.out.println("numbers found");
if(leftSide.contains(".") || rightSide.contains(".")){
System.out.println("convert to doubles");
}
else{
System.out.println("convert to ints");
}
}
else{
System.out.println("no numbers found");
}
Aucun commentaire:
Enregistrer un commentaire