package crrc.stringstudytest2;public class DataTypeConverter {/*** 字符串转换为整型** @param str 输入的字符串* @return 转换后的整型,如果转换失败返回null*/public static int stringToInt(String str) {return Integer.parseInt(str);}/*** 整型转换为字符串** @param num 输入的整型* @return 转换后的字符串*/public static String intToString(int num) {return Integer.toString(num);}/*** 字符串转换为长整型** @param str 输入的字符串* @return 转换后的长整型,如果转换失败返回null*/public static long stringToLong(String str) {return Long.parseLong(str);}/*** 长整型转换为字符串** @param num 输入的长整型* @return 转换后的字符串*/public static String longToString(long num) {return Long.toString(num);}/*** 字符串转换为双精度型** @param str 输入的字符串* @return 转换后的双精度型,如果转换失败返回null*/public static double stringToDouble(String str) {return Double.parseDouble(str);}/*** 双精度型转换为字符串** @param num 输入的双精度型* @return 转换后的字符串*/public static String doubleToString(double num) {return Double.toString(num);}public static void main(String[] args) {String strInt = "123";String strLong = "11115649845616";String strDouble = "45.67";int intValue = DataTypeConverter.stringToInt(strInt);System.out.println("String to Int: " + intValue);String intToString = DataTypeConverter.intToString(intValue);System.out.println("Int to String: " + intToString);long longValue = DataTypeConverter.stringToLong(strLong);System.out.println("String to Long:" + longValue);String longToString = DataTypeConverter.longToString(longValue);System.out.println("Long to String:" + longToString);double doubleValue = DataTypeConverter.stringToDouble(strDouble);System.out.println("String to Double: " + doubleValue);String doubleToString = DataTypeConverter.doubleToString(doubleValue);System.out.println("Double to String: " + doubleToString);}
}