Mega Code Archive

 
Categories / Java Tutorial / Data Type
 

Check if a string is a valid number

public class Main {   public static void main(String[] argv) throws Exception {     String age = "1";     String height = "1.5";     String weight = "5.9";     int theAge = Integer.parseInt(age);     float theHeight = Float.parseFloat(height);     double theWeight = Double.parseDouble(weight);     System.out.println("Age: " + theAge);     System.out.println("Height: " + theHeight);     System.out.println("Weight: " + theWeight);   } }